-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Current Behavior
When a Think program is missing required run
statements or has other structural issues, the error handling is inadequate:
- Error messages lack line numbers and column information
- No source code context is provided
- String formatting errors occur when reporting issues
- Current error message:
Think Error: 'str' object has no attribute 'message'
Expected Behavior
Error handling should:
-
Properly validate program structure:
- Check for presence of required
run
statements - Verify all defined tasks are run
- Ensure all run statements reference valid tasks
- Check for presence of required
-
Provide detailed error messages with:
- Precise line and column numbers
- Relevant source code context
- Clear explanation of the issue
- Suggestions for fixing the error
-
Use proper error classes:
ThinkParserError
for syntax/structure issuesThinkPyRuntimeError
for runtime validation- Consistent error formatting
Example
Current error:
Think Error: 'str' object has no attribute 'message'
Line: None
Column: None
Context: Near token: ''
Source code:
Expected error:
Think Error: Program must contain at least one run statement
Line: 6
Column: 1
Context:
-> 6: step "Calculate":
7: score = 95
8: print(score)
9: # Missing run statement should be here
Technical Details
The fix requires:
- Implementing a
ThinkValidator
class for program structure validation - Modifying parser and interpreter error handling to use proper error classes
- Adding source code context tracking for error reporting
- Improving error message formatting and context generation
Related Files
errors.py
parser.py
interpreter.py
Labels
- bug
- error-handling
- documentation
- enhancement
Priority
High - This impacts user experience and code understanding significantly.
/cc @project-maintainers