Skip to content
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.inspect RangeError: Invalid string length #22385

Closed
ghost opened this issue Aug 18, 2018 · 3 comments
Closed

util.inspect RangeError: Invalid string length #22385

ghost opened this issue Aug 18, 2018 · 3 comments
Labels
util Issues and PRs related to the built-in util module.

Comments

@ghost
Copy link

ghost commented Aug 18, 2018

  • Version: 8.2.1
  • Platform: Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
  • Subsystem: util.inspect

I'm using winston logger which in turn uses util.inspect.
I think the object to inspect is huge thus causing this error. But regardless it shouldn't cause invalid range.

RangeError: Invalid string length
[Node] at Array.join (native)
[Node] at reduceToSingleString (util.js:840:23)
[Node] at formatValue (util.js:586:10)
[Node] at formatProperty (util.js:793:15)
[Node] at util.js:643:12
[Node] at Array.map (native)
[Node] at formatObject (util.js:642:15)
[Node] at formatValue (util.js:582:16)
[Node] at formatProperty (util.js:793:15)
[Node] at util.js:643:12
[Node] at Array.map (native)
[Node] at formatObject (util.js:642:15)
[Node] at formatValue (util.js:582:16)
[Node] at formatProperty (util.js:793:15)
[Node] at util.js:643:12
[Node] at Array.map (native)
[Node] at formatObject (util.js:642:15)
[Node] at formatValue (util.js:582:16)
[Node] at inspect (util.js:197:10)
[Node] at Format.module.exports.format [as transform] (/Users/xx/node_modules/logform/pretty-print.js:14:19)

@vsemozhetbyt
Copy link
Contributor

FWIW, concerning string limits in Node.js (V8), see #9489 with comments.

@addaleax addaleax added the util Issues and PRs related to the built-in util module. label Aug 24, 2018
@BridgeAR
Copy link
Member

BridgeAR commented Nov 30, 2018

This got addressed by automatically limiting the maximum string length to round about 128 MB. When exceeding that limit the object will only be inspected in a minimal fashion instead of this error.

Please note that the current way of detecting this is a heuristic and will not work for a few cases with huge single strings at the end (e.g., so the total is already 100 MB and now a single string is added which alone almost has the maximum string length of ~ 2 ** 30. Here the heuristic will fail and the error will still pop up).

I don't think that there's much more on our side that we can improve here. Please try out newer Node.js versions to make use of the heuristic.

@BridgeAR
Copy link
Member

BridgeAR commented Nov 30, 2018

Please also leave a comment if you continue to run into this issue with the heuristic active! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

3 participants