Skip to content

Attach source position to errors and propagate position info through query execution#1226

Merged
lovasoa merged 2 commits intomainfrom
codex/normalize-sql-error-reporting-format
Mar 1, 2026
Merged

Attach source position to errors and propagate position info through query execution#1226
lovasoa merged 2 commits intomainfrom
codex/normalize-sql-error-reporting-format

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Mar 1, 2026

Motivation

  • Improve error messages by including the originating source file and span for SQL-related and arbitrary errors so users can locate problems in SQLPage sources.
  • Ensure static-optimized statements and parameter binding errors carry source position information so error reporting is consistent during query execution.

Description

  • Added a reusable helper write_source_position_info and refactored NiceDatabaseError::show_position_info to use it for consistent file/line output.
  • Introduced NicePositionedError and the constructor display_stmt_error to wrap arbitrary anyhow::Error with a SourceSpan and source file for nicer display.
  • Propagated statement positions through the pipeline by changing ParsedStatement::StaticSimpleSelect to include a query_position and updated parsing and matching sites accordingly.
  • In execute_queries, map parameter binding and static-simple-select execution errors to include statement position using with_stmt_position, while preserving ErrorWithStatus semantics.
  • Improved JSON error handling in sqlpage.link to return a clear anyhow! message for invalid parameters.
  • Added unit test test_display_stmt_error_includes_file_and_line to verify the new positioned error formatting and adjusted existing tests to the updated StaticSimpleSelect variant.

Testing

  • Ran cargo test which executed unit tests including test_display_stmt_error_includes_file_and_line and test_quote_source_with_highlight, and the SQL parsing tests updated for the StaticSimpleSelect shape; all tests passed.

Codex Task

@lovasoa lovasoa merged commit c822b55 into main Mar 1, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant