Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty source_line on JsError, after upgrading deno_core #961

Open
liorcode opened this issue Nov 12, 2024 · 3 comments
Open

Empty source_line on JsError, after upgrading deno_core #961

liorcode opened this issue Nov 12, 2024 · 3 comments

Comments

@liorcode
Copy link

I am using deno_core to create a Js runtime (following the great https://deno.com/blog/roll-your-own-javascript-runtime blog post)

Whenever I get an error evaluating some js source, I throw the JsError and report the bad line and code, which I take from the error source_line property.

After upgrading deno_core from 0.294 to the latest (0.319), I've noticed the source_line is always None.

Example:

Evaluating this broken code: console.log("test"
would lead to this error:

JsError { name: Some("SyntaxError"), message: Some("missing ) after argument list"), stack: None, cause: None, exception_message: "Uncaught SyntaxError: missing ) after argument list", frames: [JsStackFrame { type_name: None, function_name: None, method_name: None, file_name: Some("test1"), line_number: Some(1), column_number: Some(13), ... }], source_line: Some("console.log(\"test\""), source_line_frame_index: Some(0), aggregated: None }

and after the upgrade, it leads to this error:

JsError { name: Some("SyntaxError"), message: Some("missing ) after argument list"), stack: None, cause: None, exception_message: "Uncaught SyntaxError: missing ) after argument list", frames: [JsStackFrame { type_name: None, function_name: None, method_name: None, file_name: Some("test1"), line_number: Some(1), column_number: Some(13), ... }], source_line: None, source_line_frame_index: Some(0), aggregated: None }

(notice the None source_line)

Some findings:

I tried bisecting to find where this problem first occurred, and it seems somewhere between 0.294 and 0.298 (not sure the exact version, since some of them didn't work at all for me)
I compared the versions: 0.294.0...0.298.0

and I found this change in Error trace, which seems related: #827

specifically, the change in error.rs:
https://github.com/denoland/deno_core/pull/827/files#diff-c8dcedfc29d534d8c70ded455f342bedc1611fb609bc5e62a379004fb496cc65

Perhaps removing the "fallback" behavior in the else is the cause for the missing source_line @bartlomieju?
(the `source_line = msg.get_source_line(scope) part)

@bartlomieju
Copy link
Member

IIRC the idea was that SourceMapGetter was supposed to always return the source line. Do you use one in your code?

@liorcode
Copy link
Author

liorcode commented Nov 12, 2024

I don't think I use one. I don't even use a module loader - I just evaluate the code in something similar to:

let mut rt = JsRuntimeForSnapshot::new(RuntimeOptions { ..Default::default() });
let code = ModuleCodeString::from(script.code);
rt.execute_script(file_name, code)?;

where code, in the example is console.log("test"

@liorcode
Copy link
Author

Any suggestions @bartlomieju? Is this expected when a source map getter is not used? Because now I don't have a way to know what the defective code is (just line number)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants