Skip to content

Fix token validation error by adding transformation layer for WebAssembly response#22

Merged
MasonChow merged 4 commits intomainfrom
copilot/fix-21
Sep 4, 2025
Merged

Fix token validation error by adding transformation layer for WebAssembly response#22
MasonChow merged 4 commits intomainfrom
copilot/fix-21

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 4, 2025

The source map parser was failing with "Invalid token: sourceCode must be an array" error when parsing JavaScript error stack traces. This was preventing users from successfully mapping minified stack traces back to their original source code locations.

Root Cause

The issue was a naming convention mismatch between the WebAssembly module response and the TypeScript interface validation:

WebAssembly Module Response (snake_case):

{
  "line": 9,
  "column": 10,
  "source_code": [
    {
      "line": 8,
      "is_stack_line": false,
      "raw": "  useEffect(() => {"
    }
  ],
  "src": "../../src/App.jsx"
}

TypeScript Interface (camelCase):

interface Token {
  sourceCode: SourceCode[]; // Expected camelCase, got snake_case
}

interface SourceCode {
  isStackLine: boolean; // Expected camelCase, got snake_case
}

Solution

Added a transformToken() method that converts the WebAssembly response format to match the TypeScript interfaces:

  • source_codesourceCode
  • is_stack_lineisStackLine

This transformation happens before token validation, ensuring the structure matches the expected interface while maintaining type safety.

Testing

Added comprehensive tests that verify all 10 stack trace entries from the original issue report now parse successfully, correctly mapping to their source locations (e.g., React components, React DOM internals, scheduler functions).

The fix maintains backward compatibility and doesn't affect any existing functionality.

Fixes #21.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.jsdelivr.net
    • Triggering command: node (vitest 1) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Sep 4, 2025
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 4, 2025

@MasonChow 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] parse token error: Invalid token: sourceCode must be an array。 Fix token validation error by adding transformation layer for WebAssembly response Sep 4, 2025
Copilot AI requested a review from MasonChow September 4, 2025 14:15
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Sep 4, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.15%. Comparing base (8b3489f) to head (b537310).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #22       +/-   ##
===========================================
+ Coverage   17.64%   48.15%   +30.51%     
===========================================
  Files           5        5               
  Lines         340      353       +13     
  Branches       20       52       +32     
===========================================
+ Hits           60      170      +110     
+ Misses        278      183       -95     
+ Partials        2        0        -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MasonChow MasonChow marked this pull request as ready for review September 4, 2025 14:30
Copilot AI review requested due to automatic review settings September 4, 2025 14:30
@MasonChow MasonChow merged commit 0799087 into main Sep 4, 2025
1 check passed
Copy link
Copy Markdown
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 critical token validation error that was preventing the source map parser from successfully mapping minified JavaScript stack traces back to their original source code locations. The issue was caused by a naming convention mismatch between the WebAssembly module's snake_case response format and the TypeScript interface's camelCase expectations.

Key changes:

  • Added a transformToken() method to convert WebAssembly response format (snake_case) to TypeScript interface format (camelCase)
  • Added comprehensive test coverage for the specific stack traces mentioned in issue #21
  • Updated documentation to reflect the new transformation functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/issue-21-fix.test.ts New test file with comprehensive coverage for all 10 stack trace entries from the original issue report
src/parser.ts Added transformToken() method and integrated it into the getSourceToken() workflow
src/external/docs/guide.xml Updated documentation to include the new test file and transformation method

* @param rawToken - The raw token object from WebAssembly (uses snake_case)
* @returns Transformed token object matching the Token interface (uses camelCase)
*/
private transformToken(rawToken: any): Token {
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter type any defeats TypeScript's type safety. Define a proper interface for the raw WebAssembly response format to ensure type safety and better documentation of the expected structure.

Copilot uses AI. Check for mistakes.
line: rawToken.line,
column: rawToken.column,
src: rawToken.src,
sourceCode: rawToken.source_code?.map((sourceCode: any) => ({
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type for the sourceCode parameter in the map function reduces type safety. This should use a proper interface type for the raw source code structure.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse token error: Invalid token: sourceCode must be an array。

4 participants