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

Avoid crashing on ES module resolution when module not found #1546

Merged
merged 1 commit into from
Jan 18, 2019

Conversation

kevinkassimo
Copy link
Contributor

Closes #1545 .

See discussion #1545 (comment)

Ideally, could improve error message by providing more accurate location of import statement (using GetModuleRequestsLength() and GetModuleRequestLocation()) (However, exception value cannot be directly modified and thus we might need to introduce custom location to EncodeExceptionAsJSON, which is out of scope of this PR and might not be very useful)

@@ -0,0 +1 @@
NotFound: Cannot resolve module "./bad-module.js" from "[WILDCARD]/tests/error_009_missing_js_module.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we get a line number in the exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that custom exception gets empty stack trace, especially in ResolveCallback (GetCurrentStackTrace would not help either. I believe this is due to module resolution happening before running the code so there is not any actual stack trace)
(We can inject fake ones with correct import location hints, but this requires some extra changes to our binding layer)

For Node’s ESM solution, they do have a stack trace, but the trace is all about the JS side loader code which calls to the bindings without any information on the line/column/file of the problematic import statement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'm doing this big refactor of the module code right now - I'm going to delay landing this and/or work it into my patch...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ry Got it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind. I will just land now to avoid this crash - I doubt I will get my module stuff landed in time for the next release. I just anticipate changing this stuff soon.

Thanks for the patch!

@@ -558,7 +558,11 @@ v8::MaybeLocal<v8::Module> ResolveCallback(v8::Local<v8::Context> context,

if (d->resolve_module_.IsEmpty()) {
// Resolution Error.
isolate->ThrowException(v8_str("module resolution error"));
std::stringstream err_ss;
err_ss << "NotFound: Cannot resolve module \"" << specifier_c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this is faking an ErrorKind::NotFound...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried to simulation TS compiler error format. The problem is there is no real stack trace I could find, and there is no error passing from Rust to JS in this step (so no ErrorKind is involved). As mentioned above I could have used the two module request location calls to fake one (to show on which line of import that this error relates to) but this requires injecting something into the generated error JSON object — there is no API to directly modify the Exception object itself

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry ry merged commit f9b167d into denoland:master Jan 18, 2019
@kevinkassimo kevinkassimo deleted the esmodule/resolve_err branch December 27, 2019 07:53
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

Successfully merging this pull request may close these issues.

None yet

2 participants