From ba1ae45e5435242ba70ef377aa92450699655d2b Mon Sep 17 00:00:00 2001 From: Ju / smwhr Date: Sat, 16 Nov 2024 22:12:03 +0100 Subject: [PATCH] catch js Error on failed compilation --- script/inkjs-compiler.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/script/inkjs-compiler.ts b/script/inkjs-compiler.ts index 7a1c3492..f788791b 100644 --- a/script/inkjs-compiler.ts +++ b/script/inkjs-compiler.ts @@ -63,9 +63,14 @@ if(!inputFile.endsWith(".json")){ ) const c = new Compiler(mainInk, options); - const rstory = c.Compile(); + let rstory:Story|null = null; + try { + rstory = c.Compile(); + } catch (error: unknown) { + if((error as Error).message != "Compilation failed.") throw error; //re-throw if an illegitimate js error + } + if (!rstory) { - process.stderr.write("*** Compilation failed ***\n"); process.exit(1); } @@ -84,7 +89,7 @@ if(!inputFile.endsWith(".json")){ } }else{ if(printStats){ - process.stderr.write("warning: Could not generate stats for an already compiled story. Try it on a .ink file instead." + "\n"); + process.stderr.write("WARNING: Could not generate stats for an already compiled story. Try it on a .ink file instead." + "\n"); printStats = false; }