From 5359c54694c064cbe1a4dacb710451c39499b93f Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:44:44 +0300 Subject: [PATCH] fix: rethrow SyntaxException from compilation as EngineException --- .../me/topchetoeu/jscript/runtime/Compiler.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/java/me/topchetoeu/jscript/runtime/Compiler.java b/src/java/me/topchetoeu/jscript/runtime/Compiler.java index de430b2..70edd70 100644 --- a/src/java/me/topchetoeu/jscript/runtime/Compiler.java +++ b/src/java/me/topchetoeu/jscript/runtime/Compiler.java @@ -8,17 +8,22 @@ import me.topchetoeu.jscript.compilation.CompileResult; import me.topchetoeu.jscript.compilation.JavaScript; import me.topchetoeu.jscript.runtime.debug.DebugContext; import me.topchetoeu.jscript.runtime.exceptions.EngineException; +import me.topchetoeu.jscript.runtime.exceptions.SyntaxException; import me.topchetoeu.jscript.runtime.values.Value; import me.topchetoeu.jscript.runtime.values.functions.CodeFunction; public interface Compiler { public static final Compiler DEFAULT = (env, filename, raw) -> { - var res = JavaScript.compile(env, filename, raw); - var body = res.body(); - DebugContext.get(env).onSource(filename, raw); - registerFunc(env, body, res); - - return body; + try { + var res = JavaScript.compile(env, filename, raw); + var body = res.body(); + DebugContext.get(env).onSource(filename, raw); + registerFunc(env, body, res); + return body; + } + catch (SyntaxException e) { + throw EngineException.ofSyntax(e.loc + ": " + e.msg); + } }; public Key KEY = Key.of();