Skip to content

Commit

Permalink
src: fix regression that a source marker is lost
Browse files Browse the repository at this point in the history
PR-URL: #43086
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Coe <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
  • Loading branch information
cola119 authored and danielleadams committed Jul 26, 2022
1 parent 5aa3b21 commit 2c47e58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ static std::string GetErrorSource(Isolate* isolate,
// added in the JavaScript context:
Environment* env = Environment::GetCurrent(isolate);
const bool has_source_map_url =
!message->GetScriptOrigin().SourceMapUrl().IsEmpty();
!message->GetScriptOrigin().SourceMapUrl().IsEmpty() &&
!message->GetScriptOrigin().SourceMapUrl()->IsUndefined();
if (has_source_map_url && env != nullptr && env->source_maps_enabled()) {
return sourceline;
}
Expand Down
11 changes: 9 additions & 2 deletions test/parallel/test-error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const assert = require('assert');
const exec = require('child_process').exec;
const fixtures = require('../common/fixtures');

function errExec(script, callback) {
const cmd = `"${process.argv[0]}" "${fixtures.path(script)}"`;
function errExec(script, option, callback) {
callback = typeof option === 'function' ? option : callback;
option = typeof option === 'string' ? option : '';
const cmd = `"${process.argv[0]}" ${option} "${fixtures.path(script)}"`;
return exec(cmd, (err, stdout, stderr) => {
// There was some error
assert.ok(err);
Expand Down Expand Up @@ -79,3 +81,8 @@ errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n\r?\nNode\.js \S+\r?\n$/);
}));

// Regression tests for https://github.com/nodejs/node/issues/39149
errExec('throws_error7.js', '--enable-source-maps', common.mustCall((err, stdout, stderr) => {
assert.match(stderr, /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n\r?\nNode\.js \S+\r?\n$/);
}));

0 comments on commit 2c47e58

Please sign in to comment.