GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — util: truncate inspect array and typed array by jasnell · Pull Request #6334 · nodejs/node

Conversation

@jasnell

@jasnell jasnell commented Apr 21, 2016

Copy link
Copy Markdown
Member
Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

util

Description of change

As an alternative to #5070, set the max length of Arrays/TypedArrays in util.inspect() to 100 and provide a maxArrayLength option to override.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mik01aj and benjamingr reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@jasnell jasnell added util Issues and PRs related to the built-in util module. semver-major PRs that contain breaking changes and should be released in the next major version. labels Apr 21, 2016
@jasnell jasnell mentioned this pull request Apr 21, 2016
util: compact inspect() for sparse arrays #5070
Closed
@jasnell

jasnell commented Apr 22, 2016

Copy link
Copy Markdown
Member Author

Refs: #4905

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 22, 2016

Copy link
Copy Markdown
Member Author

Refs: #3648

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax reviewed Apr 22, 2016
View reviewed changes
Comment thread doc/api/util.md Outdated

@addaleax addaleax Apr 22, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

tiny nits: Maybe capitalize Array elements consistently in this line, and enclose the constant 0 in backticks?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@addaleax

addaleax commented Apr 22, 2016

Copy link
Copy Markdown
Member

Maybe copy the added tests to cover TypedArray, too? Either way, LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell force-pushed the util-inspect-array branch from 5b8f4bb to 12c33ae Compare April 22, 2016 18:09
@jasnell

jasnell commented Apr 22, 2016

Copy link
Copy Markdown
Member Author

@addaleax ... done! ;-)

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

What's so special about arrays? Why not make it a more general maxBytes that would apply to objects and strings too? -1 from me in the current form.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

Oh, and the option for infinity is inconsistent with the depth option of the same function, where null means unrestricted logging.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 22, 2016

Copy link
Copy Markdown
Member Author

We already have depth for objects. Would not be opposed to adding a limit for strings. maxBytes could be a bit difficult to track based on how inspect is building things out. Not impossible, of course, just a bit more complicated. Perhaps we can make the option maxLength and have it mean maximum number of characters when inspecting a string, and mean maximum number of elements when inspecting an array?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@estliberitas
estliberitas force-pushed the master branch 2 times, most recently from 7da4fd4 to c7066fb Compare April 26, 2016 05:23
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

oh, and to answer the question about what's special about arrays ... attempting to inspect an array that's too large brings the node process down. I have no issue with evolving this to place other limits, but limiting the array output is the bit we currently have open issues on. See #5070

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell force-pushed the util-inspect-array branch from 12c33ae to 67acb26 Compare April 29, 2016 06:01
@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

Updated, PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Apr 29, 2016

Copy link
Copy Markdown
Member

Still LGTM.

I’d say arrays are also special because they are the appropriate data type for (possibly large amounts) of homogeneous data, so omitting out a number of items is probably usually okay. Maybe something like this change would make sense for strings too, but not for objects, because there would be no natural way of guessing which keys to leave out when printing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 29, 2016

Copy link
Copy Markdown
Member Author

@silverwind ... any further thoughts on this? do you still object?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented Apr 30, 2016

Copy link
Copy Markdown
Contributor

@jasnell no, seems reasonable. I'm only concerned about the option. depth takes null, maxArrayLength takes null or Infinity. How about making it just null for consistency?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 30, 2016

Copy link
Copy Markdown
Member Author

@silverwind ... I can do that... but how about only in docs? If someone happens to pass Infinity it would still just work.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Apr 30, 2016

Copy link
Copy Markdown
Member

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
jasnell force-pushed the util-inspect-array branch from 67acb26 to 73524c6 Compare April 30, 2016 20:49
@jasnell

jasnell commented Apr 30, 2016

Copy link
Copy Markdown
Member Author

CI: https://ci.nodejs.org/job/node-test-pull-request/2443/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Apr 30, 2016

Copy link
Copy Markdown
Member Author

@silverwind ... updated the doc to only mention setting maxArrayLength to null to specify no limit. Infinity can still be passed and it would work, but the only documented option is null to keep it consistent. Also made one other minor cleanup tweak. Running CI now. Assuming CI is green and there are no objections, I'll land on Monday.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 1, 2016

Copy link
Copy Markdown
Member Author

CI is green.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fishrock123
Fishrock123 reviewed May 2, 2016
View reviewed changes
Comment thread doc/api/util.md Outdated

@Fishrock123 Fishrock123 May 2, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why not just set to Infinity for all elements?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasnell jasnell May 2, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

See prior discussion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fishrock123

Fishrock123 commented May 2, 2016

Copy link
Copy Markdown
Contributor

lgtm if nits are addressed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 2, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

If this is already major, maybe prefer moving the preference to Infinity over null for the other option? Or would it be better to do that in a new PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented May 2, 2016

Copy link
Copy Markdown
Contributor

Infinity also work on depth, so I guess it's fine to leave it undocumented:

> util.inspect({a:{a:{a:{a:1}}}})
'{ a: { a: { a: [Object] } } }'
> util.inspect({a:{a:{a:{a:1}}}}, {depth: null})
'{ a: { a: { a: { a: 1 } } } }'
> util.inspect({a:{a:{a:{a:1}}}}, {depth: Infinity})
'{ a: { a: { a: { a: 1 } } } }'

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 2, 2016

Copy link
Copy Markdown
Member Author

@silverwind @addaleax @mcollina ... any thoughts on whether this has to be semver-major or do you think we can treat it as a bug fix?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 2, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

I don't think very many changes to util.inspect() should be considered major. It's primary purpose is creating human-readable output.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@silverwind

silverwind commented May 2, 2016

Copy link
Copy Markdown
Contributor

I guess semver-minor would be fine.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented May 2, 2016

Copy link
Copy Markdown
Member

+1 to semver-minor.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell added semver-minor PRs that contain new features and should be released in the next minor version. and removed semver-major PRs that contain breaking changes and should be released in the next major version. labels May 2, 2016
@jasnell
jasnell force-pushed the util-inspect-array branch from 73524c6 to 41cc07e Compare May 3, 2016 17:59
@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

New CI after rebase: https://ci.nodejs.org/job/node-test-pull-request/2484/
will land after if it's green.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell
util: truncate inspect array and typed array
2b87241
As an alternative to nodejs#5070,
set the max length of Arrays/TypedArrays in util.inspect() to
`100` and provide a `maxArrayLength` option to override.
@jasnell
jasnell force-pushed the util-inspect-array branch from 41cc07e to 2b87241 Compare May 3, 2016 18:36
@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

Green. unrelated flaky timeout in rpi.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell added a commit that referenced this pull request May 3, 2016
@jasnell
util: truncate inspect array and typed array
a2e5719
As an alternative to #5070,
set the max length of Arrays/TypedArrays in util.inspect() to
`100` and provide a `maxArrayLength` option to override.

PR-URL: #6334
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

Landed in a2e5719

mik01aj reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell jasnell closed this May 3, 2016
This was referenced May 3, 2016
Node crashes when a big sparse array is given to console.log (might cause DoS) #4905
Closed
util.inspect is not so hot on large typed arrays #3648
Closed
@mcollina

mcollina commented May 3, 2016

Copy link
Copy Markdown
Member

Ok for semver-minor.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 3, 2016

Copy link
Copy Markdown
Member Author

Thank you @mcollina :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fishrock123 pushed a commit that referenced this pull request May 4, 2016
@jasnell @Fishrock123
util: truncate inspect array and typed array
91ab769
As an alternative to #5070,
set the max length of Arrays/TypedArrays in util.inspect() to
`100` and provide a `maxArrayLength` option to override.

PR-URL: #6334
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
This was referenced May 4, 2016
Propose v6.1.0 wrong base please ignore #6556
Closed
Propose v6.1.0 (Openssl update) #6557
Merged
joelostrowski pushed a commit to joelostrowski/node that referenced this pull request May 4, 2016
@jasnell @joelostrowski
util: truncate inspect array and typed array
0b03189
As an alternative to nodejs#5070,
set the max length of Arrays/TypedArrays in util.inspect() to
`100` and provide a `maxArrayLength` option to override.

PR-URL: nodejs#6334
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
cd7b76e
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
  - Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
  - Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
    - This is set to `100` by default.
  - Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
    - Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
7f82130
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
  - Please see our blog post for more info on the security contents of this release:
  - https://nodejs.org/en/blog/vulnerability/openssl-may-2016/
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
  - Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
  - Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
    - This is set to `100` by default.
  - Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
    - Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
Fishrock123 added a commit that referenced this pull request May 5, 2016
@Fishrock123
2016-05-05, Version 6.1.0 (Current)
b9ceb42
* assert: `deep{Strict}Equal()` now works correctly with circular
references. (Rich Trott) #6432
* debugger: Arrays are now formatted correctly in the debugger repl.
(cjihrig) #6448
* deps: Upgrade OpenSSL sources to 1.0.2h (Shigeki Ohtsu)
#6550
- Please see our blog post for more info on the security contents of
this release:
- https://nodejs.org/en/blog/vulnerability/openssl-may-2016/
* net: Introduced a `Socket#connecting` property. (Fedor Indutny)
#6404
- Previously this information was only available as the undocumented,
internal `_connecting` property.
* process: Introduced `process.cpuUsage()`. (Patrick Mueller)
#6157
* stream: `Writable#setDefaultEncoding()` now returns `this`.
(Alexander Makarenko) #5040
* util: Two new additions to `util.inspect()`:
- Added a `maxArrayLength` option to truncate the formatting of
Arrays. (James M Snell) #6334
- This is set to `100` by default.
- Added a `showProxy` option for formatting proxy intercepting
handlers. (James M Snell) #6465
- Inspecting proxies is non-trivial and as such this is off by
default.

PR-URL: #6557
@BridgeAR BridgeAR mentioned this pull request Aug 25, 2018
util: improve util inspect performance #22503
Closed
4 tasks done
@lydell lydell mentioned this pull request May 1, 2022
Truncate long Set and Map in util.inspect/console.log/REPL, just like long Array #42933
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@jasnell @addaleax @silverwind @mcollina @Fishrock123
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.