Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

  • Understand the issue: Need to improve error messages with file, line, source code, and stack trace
  • Analyze current implementation in script.rs and lib.rs
  • Identify V8 Message API available through TryCatch
  • Create helper function to format errors with V8 Message API
  • Update script.rs to use V8 Message for better error formatting
  • Update module.rs error handling for compilation errors
  • Update lib.rs error handling in import and run_script
  • Test with syntax errors to verify file/line/source display
  • Test with runtime errors to verify stack trace display
  • Update test expectations in test_api.rs
  • Run all tests to ensure no regressions
  • Fix formatting and clippy warnings
  • Fix code formatting issue in lib.rs that was causing CI to fail

Changes Made

Enhanced Error Formatting

  • Added format_exception() function in error.rs that extracts detailed information from V8's Message API
  • Error messages now include:
    • File path and line number (e.g., /tmp/test_error.js:2)
    • Source code line with the error
    • Caret indicator (^^^) pointing to the error location
    • Original error message
    • Full stack trace for runtime errors

Updated Error Handling

  • script.rs: Modified to return formatted error strings instead of V8 values
  • module.rs: Enhanced resolve() to catch and format compilation errors
  • lib.rs: Updated import() to properly handle and format both compilation and runtime errors

Test Updates

  • Updated test_api.rs expectations to match new error format
  • All existing tests pass with the new error format

Build Fix

  • Fixed code formatting in lib.rs to comply with rustfmt requirements

Example Output

Syntax Error:

/tmp/test_error.js:2
results['dynamic import'] = typeof import === 'function';
                                          ^^^

SyntaxError: Unexpected token '==='

Runtime Error with Stack Trace:

Error: Something went wrong
    at baz (/tmp/test_stack.js:10:11)
    at bar (/tmp/test_stack.js:6:5)
    at foo (/tmp/test_stack.js:2:5)
    at /tmp/test_stack.js:13:1
Original prompt

This section details on the original issue you should resolve

<issue_title>Improve errors</issue_title>
<issue_description>Right now errors don't have details about source file, line number, example code, or stack trace.

current error:

SyntaxError: Unexpected token '==='

error in same code /w node.js

file:///Users/mylesborins/code/testjs/test.js:312
    results['dynamic import'] = typeof import === 'function';
                                              ^^^

SyntaxError: Unexpected token '==='
    at compileSourceTextModule (node:internal/modules/esm/utils:340:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:102:18)
    at #translate (node:internal/modules/esm/loader:433:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:480:27)
    at async ModuleJob._link (node:internal/modules/esm/module_job:112:19)

Node.js v22.11.0
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #361


💡 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 changed the title [WIP] Enhance error messages with details about source and stack trace Improve error messages with file location, source code, and stack traces Oct 22, 2025
Copilot AI requested a review from MylesBorins October 22, 2025 13:11
Copilot finished work on behalf of MylesBorins October 22, 2025 13:11
@MylesBorins MylesBorins marked this pull request as ready for review October 22, 2025 13:13
@MylesBorins
Copy link
Member

@copilot the build is broken

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot the build is broken

Fixed in commit aa8d02c. The build was failing due to a code formatting issue in lib.rs. The code now passes all CI checks including fmt, clippy, and tests.

Copilot finished work on behalf of MylesBorins October 22, 2025 13:54
@MylesBorins MylesBorins merged commit adf4a33 into main Oct 22, 2025
6 checks passed
@MylesBorins MylesBorins deleted the copilot/improve-error-messages branch October 22, 2025 15:45
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.

Improve errors

2 participants