-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: truncate inspect array and typed array #6334
Conversation
Refs: #4905 |
Refs: #3648 |
@@ -179,6 +179,10 @@ formatted string: | |||
- `customInspect` - if `false`, then custom `inspect(depth, opts)` functions | |||
defined on the objects being inspected won't be called. Defaults to `true`. | |||
|
|||
- `maxArrayLength` - specifies the maximum number of Array and TypedArray | |||
elements to include when formatting. Defaults to `100`. Set to `Infinity` | |||
to show all Array elements. Set to 0 or negative to show no array elements. |
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?
Maybe copy the added tests to cover TypedArray, too? Either way, LGTM. |
5b8f4bb
to
12c33ae
Compare
@addaleax ... done! ;-) |
What's so special about arrays? Why not make it a more general |
Oh, and the option for infinity is inconsistent with the |
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 |
7da4fd4
to
c7066fb
Compare
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 |
12c33ae
to
67acb26
Compare
Updated, PTAL |
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. |
@silverwind ... any further thoughts on this? do you still object? |
@jasnell no, seems reasonable. I'm only concerned about the option. |
@silverwind ... I can do that... but how about only in docs? If someone happens to pass |
LGTM |
67acb26
to
73524c6
Compare
@silverwind ... updated the doc to only mention setting |
CI is green. |
@@ -179,6 +179,10 @@ formatted string: | |||
- `customInspect` - if `false`, then custom `inspect(depth, opts)` functions | |||
defined on the objects being inspected won't be called. Defaults to `true`. | |||
|
|||
- `maxArrayLength` - specifies the maximum number of Array and TypedArray | |||
elements to include when formatting. Defaults to `100`. Set to `null` to | |||
show all array elements. Set to `0` or negative to show no array elements. |
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?
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.
lgtm if nits are addressed |
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? |
> 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 |
@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? |
I don't think very many changes to |
I guess |
+1 to semver-minor. |
73524c6
to
41cc07e
Compare
New CI after rebase: https://ci.nodejs.org/job/node-test-pull-request/2484/ |
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.
41cc07e
to
2b87241
Compare
Green. unrelated flaky timeout in rpi. |
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 <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Landed in a2e5719 |
Ok for semver-minor. |
Thank you @mcollina :-) |
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 <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
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 <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
* 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
* 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
* 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
Checklist
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 amaxArrayLength
option to override.