Skip to content

Commit b5d37cd

Browse files
authored
lib: fix ERR_INVALID_ARG_TYPE with --enable-source-maps
Signed-off-by: June Kim <kimjune01@gmail.com> PR-URL: #63215 Fixes: #63169 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 9f0ce45 commit b5d37cd

6 files changed

Lines changed: 70 additions & 2 deletions

File tree

lib/internal/errors/error_source.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ function getErrorSourceLocation(error) {
3232
startColumn,
3333
} = pos;
3434

35+
if (!sourceLine) {
36+
return;
37+
}
38+
3539
// Source map is not enabled. Return the source line directly.
3640
if (!getSourceMapsSupport().enabled) {
3741
return { sourceLine, startColumn };
3842
}
3943

4044
const sm = findSourceMap(scriptResourceName);
4145
if (sm === undefined) {
42-
return;
46+
// No source map for this file; use the generated source line.
47+
return { sourceLine, startColumn };
4348
}
4449
const {
4550
originalLine,
@@ -49,7 +54,9 @@ function getErrorSourceLocation(error) {
4954
const originalSourceLine = getSourceLine(sm, originalSource, originalLine, originalColumn);
5055

5156
if (!originalSourceLine) {
52-
return;
57+
// Source map exists but original source is unavailable; use the
58+
// generated source line rather than returning undefined.
59+
return { sourceLine, startColumn };
5360
}
5461

5562
return {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Flags: --enable-source-maps
2+
3+
import '../../../common/index.mjs';
4+
import { strict as assert } from 'node:assert';
5+
6+
// Regression test for https://github.com/nodejs/node/issues/63169
7+
// Under --enable-source-maps with no source map for this file, a failing
8+
// assert(value) must throw AssertionError, not TypeError ERR_INVALID_ARG_TYPE.
9+
assert(false); // eslint-disable-line no-restricted-syntax
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
node:internal/modules/run_main:<line>
2+
triggerUncaughtException(
3+
^
4+
5+
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
6+
7+
assert(false)
8+
9+
at file://<project-root>/test/fixtures/source-map/output/source_map_assert_no_source_map.mjs:9:1
10+
at <node-internal-frames>
11+
at <node-internal-frames> {
12+
generatedMessage: true,
13+
code: 'ERR_ASSERTION',
14+
actual: false,
15+
expected: true,
16+
operator: '==',
17+
diff: 'simple'
18+
}
19+
20+
Node.js <node-version>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Flags: --enable-source-maps
2+
3+
'use strict';
4+
require('../../../common');
5+
const assert = require('node:assert');
6+
7+
// Regression test for https://github.com/nodejs/node/issues/63169
8+
// Under --enable-source-maps with no source map for this file, a failing
9+
// assert.ok(value) must throw AssertionError, not TypeError ERR_INVALID_ARG_TYPE.
10+
assert.ok(false); // eslint-disable-line no-restricted-syntax
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
node:internal/assert/utils:<line>
2+
throw error;
3+
^
4+
5+
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
6+
7+
assert.ok(false)
8+
9+
at Object.<anonymous> (<project-root>/test/fixtures/source-map/output/source_map_assert_ok_no_source_map.cjs:10:8)
10+
at <node-internal-frames>
11+
at <node-internal-frames> {
12+
generatedMessage: true,
13+
code: 'ERR_ASSERTION',
14+
actual: false,
15+
expected: true,
16+
operator: '==',
17+
diff: 'simple'
18+
}
19+
20+
Node.js <node-version>

test/parallel/test-node-output-sourcemaps.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { describe, it } from 'node:test';
55

66
describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () => {
77
const tests = [
8+
{ name: 'source-map/output/source_map_assert_no_source_map.mjs' },
9+
{ name: 'source-map/output/source_map_assert_ok_no_source_map.cjs' },
810
{ name: 'source-map/output/source_map_disabled_by_api.js' },
911
{ name: 'source-map/output/source_map_disabled_by_process_api.js' },
1012
{ name: 'source-map/output/source_map_enabled_by_api.js' },

0 commit comments

Comments
 (0)