Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/internal/errors/error_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ function getErrorSourceLocation(error) {
startColumn,
} = pos;

if (!sourceLine) {
return;
}

// Source map is not enabled. Return the source line directly.
if (!getSourceMapsSupport().enabled) {
return { sourceLine, startColumn };
}

const sm = findSourceMap(scriptResourceName);
if (sm === undefined) {
return;
// No source map for this file; use the generated source line.
return { sourceLine, startColumn };
}
const {
originalLine,
Expand All @@ -49,7 +54,9 @@ function getErrorSourceLocation(error) {
const originalSourceLine = getSourceLine(sm, originalSource, originalLine, originalColumn);

if (!originalSourceLine) {
return;
// Source map exists but original source is unavailable; use the
// generated source line rather than returning undefined.
return { sourceLine, startColumn };
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Flags: --enable-source-maps

import '../../../common/index.mjs';
import { strict as assert } from 'node:assert';

// Regression test for https://github.com/nodejs/node/issues/63169
// Under --enable-source-maps with no source map for this file, a failing
// assert(value) must throw AssertionError, not TypeError ERR_INVALID_ARG_TYPE.
assert(false);

Check failure on line 9 in test/fixtures/source-map/output/source_map_assert_no_source_map.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Do not use a literal for the first argument of assert(), use assert.fail() instead or remove the call
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node:internal/modules/run_main:<line>
triggerUncaughtException(
^

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert(false)

at file://<project-root>/test/fixtures/source-map/output/source_map_assert_no_source_map.mjs:9:1
at <node-internal-frames>
at <node-internal-frames> {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '==',
diff: 'simple'
}

Node.js <node-version>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Flags: --enable-source-maps

'use strict';
require('../../../common');
const assert = require('node:assert');

// Regression test for https://github.com/nodejs/node/issues/63169
// Under --enable-source-maps with no source map for this file, a failing
// assert.ok(value) must throw AssertionError, not TypeError ERR_INVALID_ARG_TYPE.
assert.ok(false);

Check failure on line 10 in test/fixtures/source-map/output/source_map_assert_ok_no_source_map.cjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Do not use a literal for the first argument of assert(), use assert.fail() instead or remove the call
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node:internal/assert/utils:<line>
throw error;
^

AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

assert.ok(false)

at Object.<anonymous> (<project-root>/test/fixtures/source-map/output/source_map_assert_ok_no_source_map.cjs:10:8)
at <node-internal-frames>
at <node-internal-frames> {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '==',
diff: 'simple'
}

Node.js <node-version>
2 changes: 2 additions & 0 deletions test/parallel/test-node-output-sourcemaps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { describe, it } from 'node:test';

describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () => {
const tests = [
{ name: 'source-map/output/source_map_assert_no_source_map.mjs' },
{ name: 'source-map/output/source_map_assert_ok_no_source_map.cjs' },
{ name: 'source-map/output/source_map_disabled_by_api.js' },
{ name: 'source-map/output/source_map_disabled_by_process_api.js' },
{ name: 'source-map/output/source_map_enabled_by_api.js' },
Expand Down
Loading