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
TON001ParseUnexpected token
TON002ParseUnterminated string
TON003ParseInvalid number format
TON101ValidationType mismatch
TON102ValidationRequired field missing
TON103ValidationValue out of range
TON201SchemaInvalid schema syntax
TON202SchemaUnknown 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