fix: return error instead of panicking on append with mismatched columns#6025
Open
prql-bot wants to merge 1 commit into
Open
fix: return error instead of panicking on append with mismatched columns#6025prql-bot wants to merge 1 commit into
prql-bot wants to merge 1 commit into
Conversation
`append`-ing two relations with a different number of columns (or with columns of incompatible types) crashed the compiler with a `todo!()` panic in `type_intersection` rather than producing a compile error. Since the column shape comes directly from user queries, this violated the "never panic on user input" rule. Thread a `Result` through `type_intersection` / `type_intersection_of_tuples` / `maybe_type_intersection` and replace the three `todo!()` calls with proper `Error` returns. The `append` call site attaches the input relation's span so the error points at the offending pipeline. This does not change the eventual semantics of column-mismatched `append` (tracked in #4724 / #5165 / #5349) — it only converts the panic into a graceful, recoverable error. Co-Authored-By: Claude Opus 4.8 <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.
Problem
Compiling an
appendof two relations with a different number of columns crashesprqlcwith a panic instead of returning a compile error:The column shape comes straight from the user's query, so this is a panic on user input — which
CLAUDE.mdexplicitly forbids ("Never panic on user input or recoverable errors"). A secondtodo!()(the catch-all arm intype_intersection) is reachable the same way when the appended columns have incompatible types (e.g.intvsfloat).Fix
type_intersection,type_intersection_of_tuples, andmaybe_type_intersectionnow returnResult<Ty>, and the threetodo!()calls become properErrorreturns. Theappendcall site ininfer_type_of_special_funcattaches the input relation's span, so the error points at the offending pipeline:This is deliberately a minimal, design-neutral change: it does not decide what column-mismatched
appendshould do (that's the open question in #4724, #5165, and #5349) — it only converts an unrecoverable panic into a graceful, recoverable error. Appends with matching columns are unaffected and still compile toUNION ALL.Tests
Two regression tests in the resolver
transformsmodule assert the rendered error for the mismatched-count and incompatible-type cases. Both would panic (and abort the test run) before this change.Found during the nightly code-quality survey.