feat: improve error UX with suggestions, context, and source snippets#70
Merged
feat: improve error UX with suggestions, context, and source snippets#70
Conversation
Polishes all error messages to be clear, actionable, and contextual: - Unknown format names suggest closest match via Levenshtein distance (e.g., 'jsn' → Did you mean 'json'?) - Unknown function names suggest closest match (e.g., 'lowr' → Did you mean 'lower'?) - Cast errors include type name, value preview, path, and expected types - File errors include the full attempted path - Parse errors show line:column location - Pretty error formatter with source snippets showing line numbers and caret (^) pointing at the error column - main.rs uses pretty_print() for human-friendly stderr output - Path Display impl for readable error paths (.users.[0].name) Includes: - Levenshtein edit distance implementation (single-row DP) - suggest_closest() generic fuzzy matcher - suggest_format() and suggest_function() with all known names - format_source_snippet() for source-annotated errors - 16 new unit tests for suggestions, pretty printing, edit distance - 6 new integration tests for CLI error UX Fixes #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Polishes all error messages to be clear, actionable, and include context.
Changes
Fuzzy Suggestions
morph -f jsn→error: unknown input format: 'jsn'. Did you mean 'json'?morph -t ymal→error: unknown output format: 'ymal'. Did you mean 'yml'?set .x = lowr(.x)→error: unknown function: lowr. Did you mean 'lower'?Improved Cast Errors
cannot cast array to int at .items: got [1, 2, 3], expected int-compatible type (int, float, string, bool, null)Pretty Error Formatting
pretty_print()method onMorphErrorfor human-friendly stderr outputOther Improvements
Displayimpl forPathAST node (readable.users.[0].nameformat)main.rsusespretty_print()for all error outputImplementation
suggest_closest()generic fuzzy matcher (case-insensitive, max distance threshold)suggest_format()covers all format names/aliasessuggest_function()covers all 50+ function names/aliasesformat_source_snippet()for source-annotated error displayTests
Fixes #31