Skip to content

util: honor breakLength Infinity with unlimited depth#62452

Open
Lellansin wants to merge 1 commit intonodejs:mainfrom
Lellansin:dev/issue-60475-util-inspect-breaklength-infinity
Open

util: honor breakLength Infinity with unlimited depth#62452
Lellansin wants to merge 1 commit intonodejs:mainfrom
Lellansin:dev/issue-60475-util-inspect-breaklength-infinity

Conversation

@Lellansin
Copy link
Copy Markdown

Restore single-line util.inspect() output when breakLength is Infinity
and depth is unlimited. This covers both depth: Infinity and depth: null.

Keep existing behavior for explicit non-default compact settings and for
customized util.inspect.defaultOptions.compact, so the fix only applies to
the default compact: 3 formatting behavior.

Add regression coverage for:

  • depth: Infinity
  • depth: null
  • explicit compact: 3
  • explicit compact: 1
  • customized util.inspect.defaultOptions.compact

Validation:

  • make -j8 node
  • python3 tools/test.py test/parallel/test-util-inspect.js
  • make lint

Fixes: #60475

Preserve single-line formatting for util.inspect() when breakLength is
Infinity and depth is unlimited, while keeping explicit compact settings
and customized defaultOptions.compact behavior unchanged.

Add regression coverage for depth: Infinity, depth: null, explicit
compact: 3, explicit compact: 1, and custom defaultOptions.compact.

Fixes: nodejs#60475
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Mar 27, 2026
if (ctx.currentDepth - recurseTimes < ctx.compact &&
if (((ctx.breakLength === Infinity &&
(ctx.depth === Infinity || ctx.depth === null) &&
ctx.compact === 3) ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed value seems confusing to me.

This would also require a documentation update, since our documentation is actually correct about compact limiting things in a particular way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util.inspect() ignores breakLength: Infinity when depth: Infinity is also set in some cases

3 participants