diff --git a/src/components/Code.astro b/src/components/Code.astro
index 5bf7672..ca7a7cd 100644
--- a/src/components/Code.astro
+++ b/src/components/Code.astro
@@ -12,6 +12,6 @@ const [native_html, error_type, error_message] = await native_highlighter(thpcod
{
error_message !== null && (
- {error_message}
+
)
}
diff --git a/src/components/docs/CodeError.astro b/src/components/docs/CodeError.astro
index 3a1f314..6492ac4 100644
--- a/src/components/docs/CodeError.astro
+++ b/src/components/docs/CodeError.astro
@@ -1,8 +1,8 @@
---
-const { error_type = "Unknown" } = Astro.props;
+const { error_type = "Unknown", error_message } = Astro.props;
---
{error_type} error:
-
+ {error_message}
diff --git a/src/lexer/highlighter.ts b/src/lexer/highlighter.ts
index 2de7c96..04e164c 100644
--- a/src/lexer/highlighter.ts
+++ b/src/lexer/highlighter.ts
@@ -56,7 +56,12 @@ export interface TokenizeResult {
export async function native_highlighter(code: string): Promise<[string, string, string | null]> {
let formatted_code = leftTrimDedent(code).join("\n");
- const result = await native_lex(formatted_code);
+ let result: TokenizeResult;
+ try {
+ result = await native_lex(formatted_code);
+ } catch (error) {
+ return compiler_error(formatted_code, error as Error);
+ }
if (result.Err) {
return lex_error_highlighter(formatted_code, result.Err!.Lex!);
@@ -101,6 +106,10 @@ function syntax_error_highlighter(code: string, tokens: Array, error: Syn
return [highlighted, "Syntax", error_message];
}
+function compiler_error(code: string, error: Error): [string, string, string] {
+ return [code, "Fatal Compiler", error.message];
+}
+
function highlight_tokens(input: string, tokens: Array): string {
const input_chars = input.split("");
let output = "";
@@ -192,7 +201,7 @@ const native_lex = (code: string) => new Promise((resolve, rejec
if (code === 0) {
resolve(JSON.parse(response));
} else {
- reject(error);
+ reject(new Error(error));
}
});
})