-
Notifications
You must be signed in to change notification settings - Fork 18
fix(models): Handle RangeError in sizeof for large objects #2344
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
Conversation
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.
Pull request overview
This PR fixes a RangeError that occurs when the sizeof utility function attempts to calculate the size of very large AppMap objects. The fix introduces a fallback recursive calculation when JSON.stringify fails due to V8's string length limitations.
Key Changes
- Modified
sizeoffunction to catch RangeError and use recursive size calculation as fallback - Added comprehensive unit tests for the
sizeoffunction including the RangeError fallback scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| packages/models/src/util.js | Added try-catch block to sizeof with recursive fallback logic for arrays, objects, and strings when JSON.stringify throws RangeError |
| packages/models/tests/unit/sizeof.spec.js | New test file with unit tests covering basic sizeof functionality and RangeError fallback behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses RangeError: Invalid string length when pruning large AppMaps by modifying the `sizeof` utility function in `@appland/models`. Previously, `sizeof` relied solely on `JSON.stringify(obj).length`, which can fail with `RangeError` for very large JavaScript objects (exceeding V8's string length limits). This in turn led to an uninitialized `classMap` and a subsequent `TypeError` during AppMap pruning. This change introduces a `try...catch` block around `JSON.stringify`. If a `RangeError` occurs, `sizeof` now falls back to a recursive calculation of the object's approximate serialized size. This ensures that large AppMaps can be processed without crashing. A new unit test `sizeof.spec.js` has been added to `packages/models/tests/unit/` to specifically verify this fallback mechanism using Jest mocks.
Update the build script to split 'macro.yml' content by either '\n' or '\r\n'. This fixes a build failure on Windows where carriage returns were causing regex matching to fail when parsing the YAML file.
dd6c967 to
e8abce7
Compare
|
🎉 This PR is included in version @appland/appmap-validate-v2.5.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Addresses RangeError: Invalid string length when pruning large AppMaps by modifying the
sizeofutility function in@appland/models.Previously,
sizeofrelied solely onJSON.stringify(obj).length, which can fail withRangeErrorfor very large JavaScript objects (exceeding V8's string length limits). This in turn led to an uninitializedclassMapand a subsequentTypeErrorduring AppMap pruning.This change introduces a
try...catchblock aroundJSON.stringify. If aRangeErroroccurs,sizeofnow falls back to a recursive calculation of the object's approximate serialized size. This ensures that large AppMaps can be processed without crashing.A new unit test
sizeof.spec.jshas been added topackages/models/tests/unit/to specifically verify this fallback mechanism using Jest mocks.