Skip to content

assert: ERR_INVALID_ARG_TYPE on failing assert(value) under --enable-source-maps (v26 regression) #63169

@twada

Description

@twada

Version

v26.1.0

Platform


Subsystem

assert

What steps will reproduce the bug?

Save the following as repro.mjs:

import { strict as assert } from 'node:assert';

try {
  assert(false);
} catch (e) {
  console.log(e.constructor.name, e.code, JSON.stringify(e.message));
}

Run it under Node.js v26.0.0 or later, with and without --enable-source-maps:

$ node repro.mjs
AssertionError ERR_ASSERTION "The expression evaluated to a falsy value:\n\n  assert(false)\n"

$ node --enable-source-maps repro.mjs
TypeError ERR_INVALID_ARG_TYPE "The \"message\" argument must be one of type string or function. Received undefined"

The same TypeError is thrown for assert.ok(false) and assert.strict(false). It does not appear for assert.equal, assert.strictEqual, and so on — only the auto-generated-message path used by assert(value) / assert.ok(value) is affected.

The same script on Node.js v25.9.0 (with --enable-source-maps) prints AssertionError as expected.

How often does it reproduce? Is there a required condition?

100%. The required conditions are:

  1. Node.js v26.0.0 or v26.1.0
  2. --enable-source-maps is enabled.
  3. The script that performs the assertion has no source map registered for it.
  4. A failing assert(value) or assert.ok(value) is executed without an explicit message argument.

What is the expected behavior? Why is that the expected behavior?

The same as Node.js v25.x: a failing assert(value) should throw an AssertionError instead of throwing a TypeError.

What do you see instead?

A TypeError [ERR_INVALID_ARG_TYPE]: The "message" argument must be one of type string or function. Received undefined is thrown from inside internal/assert/utils.js, before any AssertionError is constructed:

TypeError [ERR_INVALID_ARG_TYPE]: The "message" argument must be one of type string or function. Received undefined
    at innerFail (node:internal/assert/utils:135:11)
    at innerOk (node:internal/assert/utils:169:5)
    at strict (node:assert:882:3)
    ...

Additional information

When --enable-source-maps is on but no source map is registered for the script (typical for a hand-written .mjs / .cjs file), getErrorSourceLocation in lib/internal/errors/error_source.js returns undefined, then getErrMessage in lib/internal/assert/utils.js returns undefined, then innerOk passes [undefined] to the new strict innerFail, and innerFail throws ERR_INVALID_ARG_TYPE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions