mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
lib: fix ERR_INVALID_ARG_TYPE with --enable-source-maps
Signed-off-by: June Kim <kimjune01@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63215 Fixes: https://github.com/nodejs/node/issues/63169 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
6 files changed
+70
-2
No files matched your search
@@ -32,6 +32,10 @@ function getErrorSourceLocation(error) {
|
||||
startColumn,
|
||||
} = pos;
|
||||
|
||||
if (!sourceLine) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Source map is not enabled. Return the source line directly.
|
||||
if (!getSourceMapsSupport().enabled) {
|
||||
return { sourceLine, startColumn };
|
||||
@@ -39,7 +43,8 @@ function getErrorSourceLocation(error) {
|
||||
|
||||
const sm = findSourceMap(scriptResourceName);
|
||||
if (sm === undefined) {
|
||||
return;
|
||||
// No source map for this file; use the generated source line.
|
||||
return { sourceLine, startColumn };
|
||||
}
|
||||
const {
|
||||
originalLine,
|
||||
@@ -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 {
|
||||
|
||||
@@ -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); // eslint-disable-line no-restricted-syntax
|
||||
@@ -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>
|
||||
@@ -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); // eslint-disable-line no-restricted-syntax
|
||||
@@ -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>
|
||||
@@ -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' },
|
||||
|
||||
Reference in new issue
Block a user