cucumber / common

A home for issues that are common to multiple cucumber repositories
https://cucumber.io/docs
MIT License
3.36k stars 696 forks source link

[json-formatter] Cannot create a string longer than 0x1fffffe8 characters #1763

Closed nploi closed 2 years ago

nploi commented 2 years ago

Describe the bug Convert message to Json error when string too big.

Cannot create a string longer than 0x1fffffe8 characters

To Reproduce Steps to reproduce the behavior:

  1. I have cucumber-report.ndjson after run test. file size > 512MB
  2. Run cat report/message/cucumber-report.ndjson | cucumber-json-formatter --format ndjson > report/json/cucumber-report.json
  3. See error
    Cannot create a string longer than 0x1fffffe8 characters

Expected behavior Convert message to json is OK.

Your Environment

aurelien-reeves commented 2 years ago

Which cucumber are you using to generate your report? cucumber-js? cucumber-ruby? cucumber-jvm? Something else?

Could try to generate the json report with your cucumber in addition of the ndjson one? If so, does it work?

For information: we have decided to not deprecate the legacy json reporter anymore, but keeping it in maintenance mode: thus it won't be removed from the cucumber implementations, but it won't be enhanced anymore.

aslakhellesoy commented 2 years ago

Which cucumber are you using to generate your report? cucumber-js? cucumber-ruby? cucumber-jvm? Something else?

He said cucumber-js 7.3.1

@nploi have you considered using the built-in json formatter directly?

aurelien-reeves commented 2 years ago

Which cucumber are you using to generate your report? cucumber-js? cucumber-ruby? cucumber-jvm? Something else?

He said cucumber-js 7.3.1

Oh, yes, missed it. Sorry for that 😅

@nploi have you considered using the built-in json formatter directly?

That is what I suggested, yes, but you explained it simpler 😁

nploi commented 2 years ago

hello @aurelien-reeves, @aslakhellesoy,

Which cucumber are you using to generate your report? cucumber-js? cucumber-ruby? cucumber-jvm? Something else?

He said cucumber-js 7.3.1

@nploi have you considered using the built-in json formatter directly?

I used it before switching to the message formatter. when i use json formatter of cucumber-js, sometimes it get error like below

/my-project/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:180
|     this.log(JSON.stringify(features, null, 2))
|                   ^
| RangeError: Invalid string length
|     at JSON.stringify (<anonymous>)
|     at JsonFormatter.onTestRunFinished (/my-project/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:180:19)
|     at EventEmitter.<anonymous> (/my-project/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:89:14)
|     at EventEmitter.emit (events.js:412:35)
|     at EventEmitter.emit (domain.js:470:12)
|     at Coordinator.onWorkerProcessClose (/my-project/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:155:29)
|     at ChildProcess.<anonymous> (/my-project/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:117:12)
|     at ChildProcess.emit (events.js:400:28)
|     at ChildProcess.emit (domain.js:470:12)
|     at maybeClose (internal/child_process.js:1055:16)
|     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
| error Command failed with exit code 1.
aurelien-reeves commented 2 years ago

I used it before switching to the message formatter. when i use json formatter of cucumber-js, sometimes it get error like below

Sometimes or always? If sometimes, with the same features everytime? Are you able to try identify the feature which seems to be responsible for that?

vctqs1 commented 2 years ago

Sometimes or always? If sometimes, with the same features everytime? Are you able to try identify the feature which seems to be responsible for that?

Hi @aurelien-reeves

@nploi is my teammate :)) we have used JSON fomatter before and get your suggestion to migration to message formatter Not always It only happen for larger file

nploi commented 2 years ago

I used it before switching to the message formatter. when i use json formatter of cucumber-js, sometimes it get error like below

Sometimes or always? If sometimes, with the same features everytime? Are you able to try identify the feature which seems to be responsible for that?

  1. Sometimes
  2. Yes, the same features everytime.
  3. i can't identify the feature, but i guess it happen when try JSON.stringify large object.
aurelien-reeves commented 2 years ago

Do you have some attachments?

nploi commented 2 years ago

Do you have some attachments?

yes, i have, i attach texts and images every step.

aurelien-reeves commented 2 years ago

Hi @aurelien-reeves

@nploi is my teammate :)) we have used JSON fomatter before and get your suggestion to migration to message formatter Not always It only happen for larger file

Hi @vctqs1 :)

Ok, thanks for the tip.

I must say I am a little bit confused with your project :p

The message formatter to generate ndjson files is great when you want to integrate your own tooling.

There is no point into re-generating a json file with the cucumber-json-formatter standalone tool. If you still need a json file alongside the ndjson one for some reason, you can use both directly as output from cucumber (if I am not wrong 🤔)

Could you tell us more about what you are trying to achieve? What is your actual need?

1. Sometimes

2. Yes, the same features everytime.

3. i can't identify the feature, but i guess it happen when try `JSON.stringify` large object.

yes, i have, i attach texts and images every step.

It looks like your are reaching the limits of what is possible with your reports A report of 512MB is actually increasingly huge! Your errors may be related to memory limit being reached.

For example: https://stackoverflow.com/questions/29175877/json-stringify-throws-rangeerror-invalid-string-length-for-huge-objects which leads to this issue: https://github.com/nodejs/node-v0.x-archive/issues/14170

It seems you are building an intensive tool which reach the limits of what will be possible to do with cucumber json format itself. I would suggest to:

The key here is to use streams. This is how works the ndjson formatter: it streams the data. And as you can see, it seems to work properly in your case. So you could create your own custom formatter which would stream directly into your custom report format, or rely on existing ndjson but using streams too to read it rather than processing it at once.

nploi commented 2 years ago

Hi @aurelien-reeves,

Could you tell us more about what you are trying to achieve? What is your actual need?

We need the json file for generate static html from other library.

It looks like your are reaching the limits of what is possible with your reports A report of 512MB is actually increasingly huge! Your errors may be related to memory limit being reached.

For example: https://stackoverflow.com/questions/29175877/json-stringify-throws-rangeerror-invalid-string-length-for-huge-objects which leads to this issue: nodejs/node-v0.x-archive#14170

For now, I will split the test suite, it will generate small files.

Thanks for your suggestion.

aurelien-reeves commented 2 years ago

Ok, thanks for your reply

For now I consider it won't be fixed. But if other users encounter that issue, feel free to re-open it

mpkorstanje commented 2 years ago

We need the json file for generate static html from other library.

Might be worth updating that library to support the ndjson format and process the report as a stream.

nploi commented 2 years ago

Might be worth updating that library to support the ndjson format and process the report as a stream.

Look good to me!. Maybe, i will contribute that library. 👍

pavankumardmg commented 4 months ago

I encounter the same issue when I use JSON format, especially with larger reports, such as 500MB in size.

/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:185 this.log(JSON.stringify(features, null, 2)) ^ RangeError: Invalid string length at JSON.stringify () at JsonFormatter.onTestRunFinished (/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:185:19) at EventEmitter. (/app/node_modules/@cucumber/cucumber/src/formatter/json_formatter.ts:92:14) at EventEmitter.emit (node:events:532:35) at EventEmitter.emit (node:domain:488:12) at Coordinator.onWorkerProcessClose (/app/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:185:29) at ChildProcess. (/app/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:146:12) at ChildProcess.emit (node:events:520:28) at ChildProcess.emit (node:domain:488:12) at maybeClose (node:internal/child_process:1105:16)