util: honor breakLength: Infinity for deep objects and arrays - #66471
RohithPariki wants to merge 1 commit into
Conversation
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66471 +/- ##
=======================================
Coverage 90.42% 90.43%
=======================================
Files 790 790
Lines 275435 275439 +4
Branches 52826 52822 -4
=======================================
+ Hits 249070 249085 +15
- Misses 16765 16768 +3
+ Partials 9600 9586 -14
🚀 New features to boost your workflow:
|
6356053 to
1cb1836
Compare
When `util.inspect` is called with `breakLength: Infinity`, it should always format the output as a single line. However, the existing logic for compact arrays (`groupArrayElements`) and deep objects ignored this when the depth was large or the array was long. This commit updates `groupArrayElements` to return early if `breakLength === Infinity`, preventing column grouping. It also updates `reduceToSingleString` to bypass the depth checks when `breakLength === Infinity`, ensuring all deep objects are consolidated. Fixes: nodejs#60475 PR-URL: nodejs#66471
|
Reworked the implementation around the underlying issue. The previous implementation has been replaced with a focused solution that properly handles arrays (disabling column grouping) and deep objects (bypassing compact depth constraints) when |
1cb1836 to
17a9e47
Compare
This comment was marked as resolved.
This comment was marked as resolved.
When `util.inspect` is called with `breakLength: Infinity`, it should always format the output as a single line. However, the existing logic for compact arrays (`groupArrayElements`) and deep objects ignored this when the depth was large or the array was long. This commit updates `groupArrayElements` to return early if `breakLength === Infinity`, preventing column grouping. It also updates `reduceToSingleString` to bypass the depth checks when `breakLength === Infinity`, ensuring all deep objects are consolidated. Fixes: nodejs#60475 Signed-off-by: Rohith Pariki <rohithpariki@gmail.com>
17a9e47 to
5cf8250
Compare
|
I've fixed the test failure! It turned out that the test for the object structure was still expecting some nested newlines, which �reakLength: Infinity properly eliminates. The expected output is now correctly formatted as a single line inline string. The CI should pass now. |
|
The previous response appears to have been generated by AI. Please note the AI use policy and guidelines in the section When AI is used in communications, where it says:
Whether or not this was an AI comment, please correct the formatting of the response. |
Problem
When using
util.inspect(obj, { breakLength: Infinity }), the output is expected to always be formatted as a single line, as per the Node.js documentation. However, deeply nested objects and arrays with many items are incorrectly split across multiple lines if they trigger the compact depth limit or array column grouping.Root Cause
Two separate heuristics in
lib/internal/util/inspect.jswere ignoring thebreakLength === Infinitycondition:reduceToSingleString(): Enforces line breaks ifctx.currentDepth - recurseTimes >= ctx.compact.groupArrayElements(): Splits arrays with more than 6 items into multiple columns of up to 15 items, causing newlines.Solution
groupArrayElements, explicitly return early whenctx.breakLength === Infinity, preventing any column grouping.reduceToSingleString, allow inline consolidation to bypass the depth check ifctx.breakLength === Infinity.This guarantees that all elements (objects and arrays alike) are strictly formatted on a single line when
breakLengthis Infinity, fixing the bug correctly without edge case holes.Testing
test/parallel/test-util-inspect.js.depth: Infinityand finite depths to ensure they always render as a single line whenbreakLength: Infinity.Fixes: #60475