Skip to content

Conversation

@azu
Copy link
Owner

@azu azu commented Jul 7, 2025

Summary

This PR improves error messages for comment assertion parsing to address issue #45.

Changes Made

  • Enhanced error handling: Added try-catch blocks with line number information for better error reporting
  • Declaration validation: Added validation to prevent assertions on declarations (VariableDeclaration, FunctionDeclaration, etc.)
  • Line number information: All errors now include line numbers when available
  • Contextual error messages: Errors include the actual comment content and helpful suggestions

Before

@babel/template placeholder "ACTUAL_NODE": Property arguments[0] of CallExpression expected node to be of a type ["Expression","SpreadElement","ArgumentPlaceholder"] but instead got "VariableDeclaration"

After

Cannot add assertion to VariableDeclaration at line 4. Comment assertions (// => "missing expression") can only be added to expressions, not declarations. Try adding the assertion after an expression statement instead.

Additional Improvements

  • Parse errors now include line numbers: Error at line 3: Unexpected token, expected "," (1:9)
  • Clear guidance on how to fix common mistakes
  • Better developer experience with actionable error messages

Test Coverage

Added comprehensive test case to verify the improved error message format includes:

  • Line number information
  • Clear problem description
  • Helpful suggestions for resolution

Breaking Changes

None - this only improves error messages without changing functionality.

Related Issues

Fixes #45

🤖 Generated with Claude Code

azu and others added 2 commits July 7, 2025 23:34
- Add line number information to error messages
- Provide clearer error messages when trying to add assertions to declarations
- Include context about what went wrong and how to fix it
- Add try-catch error handling with line number information for parsing errors

Fixes #45

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Add test for FunctionDeclaration with assertion comment
- Add test for ClassDeclaration with assertion comment
- Add test for ImportDeclaration with assertion comment
- Ensure all declaration types are properly validated with line numbers

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@azu azu added the Type: Bug Bug or Bug fixes label Jul 7, 2025
@azu azu merged commit 64ffa9a into master Jul 7, 2025
4 checks passed
@azu azu deleted the improve-error-messages-for-comment-assertions branch July 7, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Bug or Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error messages for comment assertion parsing failures

2 participants