Skip to content

Commit

Permalink
fix: Workaround JSON.stringify failing on large arrays with the error…
Browse files Browse the repository at this point in the history
… "RangeError: Invalid string length" when downloading profiling (#2050)
  • Loading branch information
paddlefish committed Aug 8, 2023
1 parent 7165558 commit 1427136
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/cli-hermes/src/profileHermes/downloadProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ export async function downloadProfile(
file,
'.cpuprofile',
)}-converted.json`;

// Convert to JSON in chunks because JSON.stringify() will fail for large
// arrays with the error "RangeError: Invalid string length"
const out = events.map(JSON.stringify).join(",");

fs.writeFileSync(
transformedFilePath,
JSON.stringify(events, undefined, 4),
"["+out+"]",
'utf-8',
);
logger.success(
Expand Down

0 comments on commit 1427136

Please sign in to comment.