-
Notifications
You must be signed in to change notification settings - Fork 1
Add line number tracking for schema validation errors #64
Copy link
Copy link
Open
Labels
Description
Problem
When schema validation fails (e.g., invalid JSON, missing fields, incorrect types), error messages only show what's wrong but not where in the schema file the issue is located. Users have to manually search through the schema to find the problematic line.
Current behavior:
Schema validation failed: Invalid field type
Field 'amount' has invalid type
Desired behavior:
Schema validation failed: Invalid field type
Field 'amount':
Location: invoice.schema.json:15:5
Error: Invalid type 'int' (use 'integer' instead)
Proposed Solution
Implement position tracking during JSON parsing to map validation errors back to source locations:
- Parser enhancement: Use a JSON parser that preserves position information (e.g.,
json-source-map,jsonpos, or custom AST-based parser) - Error context: Augment validation errors with line/column numbers
- Code snippets: Optionally show the relevant lines from the schema file with error highlighting
Acceptance Criteria
- Schema validation errors include file path, line number, and column
- Error messages show a snippet of the problematic schema section
- Position tracking works for all schema validation error types
- Minimal performance impact (consider lazy loading position data)
- Works for both file-based and string-based schema inputs
Implementation Notes
This is a lower-priority enhancement because:
- Most schemas are small enough to scan visually
- Current error messages are already descriptive
- Would add dependency or complexity for position tracking
- Alternative: Users can use JSON validators/linters in their editors
Could be combined with:
- Add structured logging system #12 (structured logging) - log schema locations in debug mode
- IDE integration features in the future
Related
- Blocked by: None
- Relates to: Improve error messages for better user understanding #63 (improve error messages - this is a follow-up enhancement)
Reactions are currently unavailable