Repository navigation
fix: show the actual unsupported expression, not its opaque discriminant - #240
Merged
Merged
Conversation
…iscriminant
Five fallback arms in frontend-promql's lowering (info_selector,
lower_inner, expr_str, extract_matrix, num_expr) formatted
std::mem::discriminant(other) into their UnsupportedFeature /
InvalidParameter messages instead of the expression itself.
Discriminant's Debug output is an opaque internal value -- not the
variant name, not the source text -- so a query hitting any of these
paths produced an error that named nothing about what was actually
written. promql_parser's Expr implements Display (reconstructing
PromQL source text), so these now interpolate the expression directly.
Also fixes frontend-sql's lower_agg_intent fallback, which dumped a
DataFusion Expr's full Debug representation with no explanation of why
it was rejected -- switched to Display plus a "why" clause, matching
every other lowering error in the same file (e.g. expr_to_group_ref's
"non-column GROUP BY expression: {other}").
Found via a code review of the error-handling paths a SQL/PromQL query
follows when it hits an unsupported construct.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Oct 20, 2026
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.
Summary
Found while reviewing this codebase's error-handling paths for unsupported SQL/PromQL constructs, prompted by wanting an "unsupported X" error to always clearly say what is unsupported.
The overall error-type shapes were already in good order:
SqlError/LoweringErrorandPromqlErrorboth carry layer/category information structurally (variant names likeUnsupportedFeature/UnsupportedAggregate/TableNotFoundvs. a wrappedDataFusionError),ResolveError/QueryExprError(asap-types) already usethiserrorwith informative messages naming the actual column/name involved, andDataFusionError's ownDisplayembeds a category prefix ("Error during planning: ", "SQL error: ", "This feature is not implemented: ", "Schema error: ") thatSqlError'sDisplaypreserves verbatim.bgp_jan2024_workload'sCategorytaxonomy (Plan/Schema/Parse/NotImplemented/UnsupportedFeature/Other) already maps cleanly onto these existing variants.But one real bug: five fallback arms in
crates/frontend-promql/src/promql.rs(info_selector,lower_inner,expr_str,extract_matrix,num_expr) built theirUnsupportedFeature/InvalidParametermessage by formattingstd::mem::discriminant(other)instead ofotheritself.Discriminant<Expr>'sDebugoutput is an opaque internal value — not the enum variant name, not the source text, not anything a person could act on. A query that hit any of these paths produced an error message that literally said nothing about what the person actually wrote.promql_parser::parser::ast::ExprimplementsDisplay(it reconstructs PromQL source text), so this swapsformat!("... {:?}", std::mem::discriminant(other))forformat!("...{other}")at all five sites — the message now shows the actual offending sub-expression.Also fixes a related, less severe case in
crates/frontend-sql/src/sql/mod.rs'slower_agg_intentfallback: it dumped a DataFusionExpr's fullDebugrepresentation (verbose internal AST shape, not the pretty-printed SQL) with no explanation of why it was rejected. Switched toDisplayplus a "why" clause ("measure is not an aggregate function call: {expr}"), matching the pattern every other lowering error in the same file already uses (e.g.expr_to_group_ref's"non-column GROUP BY expression: {other}").Test plan
cargo build --workspace --all-targetscargo test --workspace(includingpromql_conformance's 100 tests,sql_lowering's 60, and thebgp_jan2024_workload200-query corpus tally — none pin the changed message text)cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warnings🤖 Generated with Claude Code