Skip to content

fix: improve error message for negative numbers in transforms#5566

Merged
max-sixty merged 4 commits intoPRQL:mainfrom
max-sixty:4315
Nov 17, 2025
Merged

fix: improve error message for negative numbers in transforms#5566
max-sixty merged 4 commits intoPRQL:mainfrom
max-sixty:4315

Conversation

@max-sixty
Copy link
Copy Markdown
Member

Fixes #4315

Summary

Improves the error message when users write expressions like take -10 or sort -name without wrapping negative numbers in parentheses.

Problem

Previously, when users wrote queries like:

from pets
take -10

They received a confusing error message:

Error: expected a pipeline that resolves to a table, but found `internal std.sub`
↳ Hint: are you missing `from` statement?

The error pointed to internal standard library code and suggested adding a from statement, which was not helpful since the actual issue is that -10 is being parsed as a subtraction operation.

Solution

The fix detects when the error involves internal std.sub (subtraction) and provides a context-specific hint:

Error: expected a pipeline that resolves to a table, but found `internal std.sub`
↳ Hint: wrap negative numbers in parentheses, e.g. `sort (-column_name)`

This guides users to the correct syntax: take (-10) or sort (-name).

Changes

  • Modified lower_table_ref function in lowering.rs to detect internal std.sub pattern
  • Provides specific hint for wrapping negative expressions in parentheses
  • Added test case take_negative_number for issue Unhelpful error with take -10 #4315
  • Updated existing test snapshots for sort -name and group id (sort -val) cases

Test Plan

All 608 tests pass. The new error message is verified in three test cases:

  • take_negative_number - new test for issue Unhelpful error with take -10 #4315
  • test_bad_error_messages - updated sort -name case
  • invalid_lineage_in_transform - updated group id (sort -val) case

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

max-sixty and others added 4 commits November 17, 2025 14:35
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>
@max-sixty max-sixty merged commit 6ffa6ef into PRQL:main Nov 17, 2025
35 of 36 checks passed
@max-sixty max-sixty deleted the 4315 branch November 17, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhelpful error with take -10

1 participant