Error Handling
Guidelines for error handling and reporting in TON implementations.
Error Categories
Parse Errors
- Syntax errors
- Unexpected tokens
- Unterminated strings
- Invalid number formats
Validation Errors
- Type mismatches
- Missing required fields
- Constraint violations
- Invalid enum values
Schema Errors
- Invalid schema syntax
- Undefined type references
- Circular dependencies
Error Reporting
Errors should include:
- Location: Line and column numbers
- Context: Surrounding text
- Message: Clear description
- Suggestion: How to fix (when possible)
Error at line 5, column 12:
name = John Doe
^
Expected quoted string value
Suggestion: Use quotes around string values: "John Doe"
Recovery Strategies
Parser Recovery
- Skip to next valid token
- Insert missing tokens
- Continue parsing after errors
- Collect multiple errors
Validation Recovery
- Apply default values
- Continue validation
- Mark invalid sections
Error Codes
Code | Category | Description |
---|---|---|
TON001 | Parse | Unexpected token |
TON002 | Parse | Unterminated string |
TON003 | Parse | Invalid number format |
TON101 | Validation | Type mismatch |
TON102 | Validation | Required field missing |
TON103 | Validation | Value out of range |
TON201 | Schema | Invalid schema syntax |
TON202 | Schema | Unknown type reference |
Best Practices
- Always include location information
- Provide actionable error messages
- Collect all errors before stopping
- Suggest fixes when possible
- Use consistent error formatting