Skip to content

Conversation

@dividedmind
Copy link
Collaborator

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.

@dividedmind dividedmind self-assigned this Dec 29, 2025
@dividedmind dividedmind added the build native Build and save native packages in the GitHub workflow label Dec 29, 2025
@dividedmind dividedmind added the bug Something isn't working label Dec 29, 2025
Copy link
Contributor

Copilot AI left a 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 sizeof function to catch RangeError and use recursive size calculation as fallback
  • Added comprehensive unit tests for the sizeof function 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.
@dividedmind dividedmind force-pushed the fix/large-appmap-pruning branch from dd6c967 to e8abce7 Compare December 29, 2025 10:18
@dividedmind dividedmind merged commit 8ea29cb into main Jan 4, 2026
29 checks passed
@dividedmind dividedmind deleted the fix/large-appmap-pruning branch January 4, 2026 05:14
@appland-release
Copy link
Contributor

🎉 This PR is included in version @appland/appmap-validate-v2.5.1 🎉

The release is available on:

  • @appland/appmap-validate-v2.5.1
  • GitHub release
  • @appland/appmap-validate-v2.5.1

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build native Build and save native packages in the GitHub workflow released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants