fix: improve error message for negative numbers in transforms#5566
Merged
fix: improve error message for negative numbers in transforms#5566
Conversation
Fixes PRQL#4315 When users write `take -10` or `sort -name`, the error now provides a helpful hint to wrap the expression in parentheses instead of the generic "are you missing `from` statement?" message. Changes: - Detect `internal std.sub` pattern in error messages - Provide specific hint: "wrap negative numbers in parentheses, e.g. `sort (-column_name)`" - Add test case for `take -10` scenario - Update existing test snapshots 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts in lowering.rs and bad_error_messages.rs: - Kept improved error hint for negative numbers (our changes) - Updated fallback hint to match main's wording: "`from` statement might be missing?" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Moves tests with good error messages from bad_error_messages.rs to
error_messages.rs:
- negative_number_in_transform (for sort -name, take -10, group with sort -val)
- empty_tuple_or_array_from (from {}, from [], from {} select a)
These error messages now provide helpful hints and clear error messages,
so they belong in error_messages.rs rather than bad_error_messages.rs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Fixes #4315
Summary
Improves the error message when users write expressions like
take -10orsort -namewithout wrapping negative numbers in parentheses.Problem
Previously, when users wrote queries like:
They received a confusing error message:
The error pointed to internal standard library code and suggested adding a
fromstatement, which was not helpful since the actual issue is that-10is being parsed as a subtraction operation.Solution
The fix detects when the error involves
internal std.sub(subtraction) and provides a context-specific hint:This guides users to the correct syntax:
take (-10)orsort (-name).Changes
lower_table_reffunction inlowering.rsto detectinternal std.subpatterntake_negative_numberfor issue Unhelpful error withtake -10#4315sort -nameandgroup id (sort -val)casesTest Plan
All 608 tests pass. The new error message is verified in three test cases:
take_negative_number- new test for issue Unhelpful error withtake -10#4315test_bad_error_messages- updatedsort -namecaseinvalid_lineage_in_transform- updatedgroup id (sort -val)case🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com