Skip to content

Throwing within util.inspect.custom can cause an ERR_INTERNAL_ASSERTION #49177

Open
@paperclover

Description

@paperclover

Version

20.5.1

Platform

Darwin paperback.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 arm64

Subsystem

No response

What steps will reproduce the bug?

import util from "util";
console.log({
  hello: {
    [util.inspect.custom]: () => {
      throw new Error("hello");
    },
  },
});

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

Every Time

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

To throw the error without an internal assertion error.

What do you see instead?

node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_INTERNAL_ASSERTION]: Error: hello
    at [nodejs.util.inspect.custom] (file:///private/tmp/scratchpad_20230815T031811/index.mjs:5:13)
    at formatValue (node:internal/util/inspect:804:19)
    at formatProperty (node:internal/util/inspect:1944:11)
    at formatRaw (node:internal/util/inspect:1053:9)
    at formatValue (node:internal/util/inspect:839:10)
    at inspect (node:internal/util/inspect:363:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2297:40)
    at formatWithOptions (node:internal/util/inspect:2159:10)
    at console.value (node:internal/console/constructor:342:14)
    at console.log (node:internal/console/constructor:379:61)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:405:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1555:10)
    at formatRaw (node:internal/util/inspect:1061:12)
    at formatValue (node:internal/util/inspect:839:10)
    at inspect (node:internal/util/inspect:363:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2297:40)
    at formatWithOptions (node:internal/util/inspect:2159:10)
    at console.value (node:internal/console/constructor:342:14)
    at console.log (node:internal/console/constructor:379:61) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v20.5.1

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions