Browse Source

updated error messages

master
Silberengel 10 months ago
parent
commit
289ee898ea
  1. 4
      src/lib/components/LoginModal.svelte
  2. 24
      src/lib/utils/markdown/advancedMarkdownParser.ts
  3. 18
      src/lib/utils/markdown/basicMarkdownParser.ts

4
src/lib/components/LoginModal.svelte

@ -27,10 +27,10 @@
if (!user) { if (!user) {
throw new Error('The NIP-07 extension did not return a user.'); throw new Error('The NIP-07 extension did not return a user.');
} }
} catch (e) { } catch (e: unknown) {
console.error(e); console.error(e);
signInFailed = true; signInFailed = true;
errorMessage = e instanceof Error ? e.message : 'Failed to sign in. Please try again.'; errorMessage = (e as Error)?.message ?? 'Failed to sign in. Please try again.';
} }
} }
</script> </script>

24
src/lib/utils/markdown/advancedMarkdownParser.ts

@ -110,13 +110,13 @@ function processTables(content: string): string {
html += '</tbody>\n</table>\n</div>'; html += '</tbody>\n</table>\n</div>';
return html; return html;
} catch (error) { } catch (e: unknown) {
console.error('Error processing table row:', error); console.error('Error processing table row:', e);
return match; return match;
} }
}); });
} catch (error) { } catch (e: unknown) {
console.error('Error in processTables:', error); console.error('Error in processTables:', e);
return content; return content;
} }
} }
@ -242,7 +242,7 @@ function processCodeBlocks(text: string): { text: string; blocks: Map<string, st
if (currentLanguage.toLowerCase() === 'json') { if (currentLanguage.toLowerCase() === 'json') {
try { try {
formattedCode = JSON.stringify(JSON.parse(code), null, 2); formattedCode = JSON.stringify(JSON.parse(code), null, 2);
} catch (e) { } catch (e: unknown) {
formattedCode = code; formattedCode = code;
} }
} }
@ -282,7 +282,7 @@ function processCodeBlocks(text: string): { text: string; blocks: Map<string, st
if (currentLanguage.toLowerCase() === 'json') { if (currentLanguage.toLowerCase() === 'json') {
try { try {
formattedCode = JSON.stringify(JSON.parse(code), null, 2); formattedCode = JSON.stringify(JSON.parse(code), null, 2);
} catch (e) { } catch (e: unknown) {
formattedCode = code; formattedCode = code;
} }
} }
@ -321,7 +321,7 @@ function restoreCodeBlocks(text: string, blocks: Map<string, string>): string {
ignoreIllegals: true ignoreIllegals: true
}).value; }).value;
html = `<pre class="code-block"><code class="hljs language-${language}">${highlighted}</code></pre>`; html = `<pre class="code-block"><code class="hljs language-${language}">${highlighted}</code></pre>`;
} catch (e) { } catch (e: unknown) {
console.warn('Failed to highlight code block:', e); console.warn('Failed to highlight code block:', e);
html = `<pre class="code-block"><code class="hljs ${language ? `language-${language}` : ''}">${code}</code></pre>`; html = `<pre class="code-block"><code class="hljs ${language ? `language-${language}` : ''}">${code}</code></pre>`;
} }
@ -330,8 +330,8 @@ function restoreCodeBlocks(text: string, blocks: Map<string, string>): string {
} }
result = result.replace(id, html); result = result.replace(id, html);
} catch (error) { } catch (e: unknown) {
console.error('Error restoring code block:', error); console.error('Error restoring code block:', e);
result = result.replace(id, '<pre class="code-block"><code class="hljs">Error processing code block</code></pre>'); result = result.replace(id, '<pre class="code-block"><code class="hljs">Error processing code block</code></pre>');
} }
} }
@ -378,8 +378,8 @@ export async function parseAdvancedMarkdown(text: string): Promise<string> {
processedText = restoreCodeBlocks(processedText, blocks); processedText = restoreCodeBlocks(processedText, blocks);
return processedText; return processedText;
} catch (error) { } catch (e: unknown) {
console.error('Error in parseAdvancedMarkdown:', error); console.error('Error in parseAdvancedMarkdown:', e);
return `<div class="text-red-500">Error processing markdown: ${error instanceof Error ? error.message : 'Unknown error'}</div>`; return `<div class=\"text-red-500\">Error processing markdown: ${(e as Error)?.message ?? 'Unknown error'}</div>`;
} }
} }

18
src/lib/utils/markdown/basicMarkdownParser.ts

@ -304,8 +304,8 @@ function processBasicFormatting(content: string): string {
processedText = output; processedText = output;
// --- End Improved List Grouping and Parsing --- // --- End Improved List Grouping and Parsing ---
} catch (error) { } catch (e: unknown) {
console.error('Error in processBasicFormatting:', error); console.error('Error in processBasicFormatting:', e);
} }
return processedText; return processedText;
@ -330,8 +330,8 @@ function processBlockquotes(content: string): string {
lines.join('\n') lines.join('\n')
}</blockquote>`; }</blockquote>`;
}); });
} catch (error) { } catch (e: unknown) {
console.error('Error in processBlockquotes:', error); console.error('Error in processBlockquotes:', e);
return content; return content;
} }
} }
@ -342,8 +342,8 @@ function processEmojiShortcuts(content: string): string {
const emojiChar = emoji.get(name); const emojiChar = emoji.get(name);
return emojiChar || `:${name}:`; return emojiChar || `:${name}:`;
}}); }});
} catch (error) { } catch (e: unknown) {
console.error('Error in processEmojiShortcuts:', error); console.error('Error in processEmojiShortcuts:', e);
return content; return content;
} }
} }
@ -396,8 +396,8 @@ export async function parseBasicMarkdown(text: string): Promise<string> {
processedText = replaceWikilinks(processedText); processedText = replaceWikilinks(processedText);
return processedText; return processedText;
} catch (error) { } catch (e: unknown) {
console.error('Error in parseBasicMarkdown:', error); console.error('Error in parseBasicMarkdown:', e);
return `<div class="text-red-500">Error processing markdown: ${error instanceof Error ? error.message : 'Unknown error'}</div>`; return `<div class="text-red-500">Error processing markdown: ${(e as Error)?.message ?? 'Unknown error'}</div>`;
} }
} }
Loading…
Cancel
Save