Errors with source code location #13650
Closed
eliaperantoni
started this conversation in
Ideas
Replies: 1 comment
-
Moved to issue #13662, so it can be linked to a PR. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Idea
We propose implementing the ability of enriching errors, such as those coming from the parsing of a SQL query into AST nodes or the build of its logical plan, with the location of the code that caused them. i.e. a
Span
.Example
For example, in the following query:
The error is that an integer and a string cannot be coerced to types such that an arithmetic operation is applicable to them, (without explicit casts). In this case, the error should highlight the third-to-last line of the query.
At the same time, it would be helpful to highlight the projected
price_usd
column in the CTE too. Not as the main error but more as a note to help the user understand the context around the error and the elements involved.Proposal
We propose adding a new variant to
DataFusionError
, let's call itDataFusionError::Diagnostics
. This variant would wrap any otherDataFusionError
, plus a vec ofDiagnosticsEntry
. Each of those is a string message together with aSpan
and akind
.Then, we could progressively add points in the logical planner where the errors are enriched with source code information by wrapping them in
DataFusionError::Diagnostics
before returning.For that to be possible, we'd have to move the
Span
to the logicalExpr
, when converting from the parser'sExpr
. See here for example. Without this, the information about the source code location is lost when the conversion happens, and the logical planner has no way to get it.Purpose of document
We'd love to hear everybody's thoughts on this hypothetical feature and the proposed solution. Whether it would cover most foreseeable solutions, whether there is a better alternative, if it should be extended to carry even more information, etc.
Beta Was this translation helpful? Give feedback.
All reactions