Skip to content

src,lib: print source map error source on demand

The source context is not prepended to the value of the stack property when the source map is not enabled. Rather than prepending the error source context to the value of the stack property unconditionally, this PR aligns the behavior and only prints the source context when the error is not handled by userland (e.g. fatal errors).

Also, this PR fixes that when source-map support is enabled, the error source context is not pointing to where the error was thrown. For a source file "test.js" like:

const err = new Error('foo');
throw err;

The source context for the thrown error should be:

test.js:2
throw err; // << where the error was thrown
^

Error: foo
    at test.js:1:13 // << where the error was created

Fixes: https://github.com/nodejs/node/issues/43186 Fixes: https://github.com/nodejs/node/issues/41541

Merge request reports

Loading