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

RangeError: Invalid string length with --format=json and a really long source line #5380

Closed
ahal opened this issue Feb 23, 2016 · 7 comments
Closed
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint

Comments

@ahal
Copy link

ahal commented Feb 23, 2016

Failure:

$ eslint --plugin html --ext "[.js,.jsm,.jsx,.xml,.html]" --format json /path/to/mozilla-central/devtools/client/inspector/markup/test
/home/ahal/.npm-global/lib/node_modules/eslint/lib/formatters/json.js:13
    return JSON.stringify(results);
                ^

RangeError: Invalid string length
    at Object.stringify (native)
    at module.exports (/home/ahal/.npm-global/lib/node_modules/eslint/lib/formatters/json.js:13:17)
    at printResults (/home/ahal/.npm-global/lib/node_modules/eslint/lib/cli.js:82:14)
    at Object.cli.execute (/home/ahal/.npm-global/lib/node_modules/eslint/lib/cli.js:173:17)
    at Object.<anonymous> (/home/ahal/.npm-global/lib/node_modules/eslint/bin/eslint.js:60:20)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)

I can consistently reproduce this running eslint on all the files in this directory:
https://dxr.mozilla.org/mozilla-central/source/devtools/client/inspector/markup/test

STR:

$ hg clone https://hg.mozilla.org/mozilla-central/
$ ./mach eslint --setup
$ eslint --plugin html --ext "[.js,.jsm,.jsx,.xml,.html]" --format json /path/to/mozilla-central/devtools/client/inspector/markup/test

Note: the path needs to be absolute to bypass the include/exclude directives in .eslintrc.

I did a bit of digging and the result set isn't terribly large (104 errors) so I found it strange that memory problems would be the issue. It turns out, that JSON.stringify falls over at this really long line:
https://dxr.mozilla.org/mozilla-central/source/devtools/client/inspector/markup/test/browser_markup_copy_image_data.js#12

which appears in the eslint output under the 'source' attribute. Though, if I lint only that specific file, it works fine. I realize this is likely a v8 bug, but might warrant a workaround in eslint to cover this case.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 23, 2016
@nzakas
Copy link
Member

nzakas commented Feb 25, 2016

This is happening because we include the line text whenever there's a lint problem on it. If there are multiple problems on that line, that probably blows out the size of the raw result.

About the only workaround I can think of would be to truncate the line if it's greater than some arbitrary length, and I'm unsure if we should do that.

Another option is for you to create a custom formatter that omits the source field from each message.

@platinumazure
Copy link
Member

Hmm. Is there really a strong need to serialize the line, anyway? Some other formatters (stylish, compact) don't bother.

Then again, it would be a breaking change to remove it unconditionally, so let me raise one more thought: Could we support formatter-specific CLI or CLIEngine options? These would be ignored by default by all formatters, but the JSON one could have an option for omitting serializing the line; in this particular case, it could be implemented as a replacer function for the JSON.stringify call.

@nzakas
Copy link
Member

nzakas commented Feb 27, 2016

Could we support formatter-specific CLI or CLIEngine options?

No, we don't want to complicate formatters by passing additional options into them. We added the JSON formatter so people could pipe that to whatever tools they wanted. See #2989

@platinumazure
Copy link
Member

In that case, should we consider adding a new formatter (maybe "simple-json" or "minimal-json") which omits some values in serialization? That would seem to be a good way to help @ahal out.

@nzakas
Copy link
Member

nzakas commented Feb 28, 2016

Most of our formatters already don't output the source text. Adding another formatter just for this purpose is a bit much, especially when it's easy to create a custom formatter that does exactly what you want.

@platinumazure
Copy link
Member

It sounds like we're deciding not to fix this in core. Closing as wontfix.

@ahal If you would like help writing a custom formatter, please feel free to reach out in our Gitter chat, and we'll do our best to help.

@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint wontfix and removed triage An ESLint team member will look at this issue soon labels Feb 28, 2016
@rtfpessoa
Copy link

rtfpessoa commented Jun 25, 2016

I am getting lots of errors in version 2.13.1:

No content to map due to end-of-input
 at [Source: java.io.StringReader@cd1e646; line: 1, column: 1]
Invalid string length
RangeError: Invalid string length
    at Object.stringify (native)
    at module.exports (/usr/lib/node_modules/eslint/lib/formatters/json.js:12:17)
    at printResults (/usr/lib/node_modules/eslint/lib/cli.js:84:14)
    at Object.cli.execute (/usr/lib/node_modules/eslint/lib/cli.js:192:17)
    at Object.<anonymous> (/usr/lib/node_modules/eslint/bin/eslint.js:77:20)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

Is there any way for me to avoid this?

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

No branches or pull requests

5 participants