Skip to content

feat: improve SQL error messages with column context and did-you-mean hint#110

Merged
vmvarela merged 3 commits intomasterfrom
issue-81/improve-sql-error-messages
Apr 29, 2026
Merged

feat: improve SQL error messages with column context and did-you-mean hint#110
vmvarela merged 3 commits intomasterfrom
issue-81/improve-sql-error-messages

Conversation

@vmvarela
Copy link
Copy Markdown
Owner

Summary

Closes #81

  • On SQL query error (exit 3), print the list of available columns from PRAGMA table_info(t) and suggest the closest match when the missing identifier has edit distance ≤ 2 from an existing column name.
  • Fix --json incorrectly rejected when combined with --delimiter / --tsv (those flags only affect input parsing, not output format).
  • Fix double-free bug in csv.zig triggered by error.UnterminatedQuotedField when manual cleanup clashed with errdefer blocks.

New behaviour

$ printf 'id,amount,region\n1,100,east\n' | sql-pipe 'SELECT amout FROM t'
error: no such column: amout
  table "t" has columns: id, amount, region
  hint: did you mean "amount"?

$ printf 'id,amount,region\n1,100,east\n' | sql-pipe 'SELECT revenue FROM t'
error: no such column: revenue
  table "t" has columns: id, amount, region

$ printf 'name,age\n"unterminated' | sql-pipe 'SELECT * FROM t'
error: row 2: unterminated quoted field

Changes

  • src/main.ziglevenshteinDistance, getTableColumns, printSqlErrorContext, fatalSqlWithContext; all post-createTable SQL errors now use fatalSqlWithContext; --json incompatibility narrowed to --header only
  • src/csv.zig — remove manual cleanup before return error.UnterminatedQuotedField (was double-freeing memory already owned by errdefer)
  • build.zig — integration tests 26 (column list on SQL error), 27 (did-you-mean hint), 28 (CSV row number), 17b (--json + --delimiter now works)
  • README.md — Exit Codes section updated with example output

@vmvarela vmvarela added this to the Sprint 5 milestone Apr 29, 2026
@vmvarela vmvarela added type:feature New functionality priority:high Must be in the next sprint size:s Small — 1 to 4 hours labels Apr 29, 2026
… hint

On SQL query errors (exit 3), print the available column names from
PRAGMA table_info(t) and suggest the closest match when the missing
identifier has Levenshtein distance ≤ 2 from an existing column.

Also fix a double-free bug in csv.zig where manual cleanup before
returning error.UnterminatedQuotedField clashed with errdefer blocks.

Closes #81
--delimiter and --tsv only affect input parsing; they are orthogonal
to the output format. Only --header (which also affects output) should
be incompatible with --json.
@vmvarela vmvarela force-pushed the issue-81/improve-sql-error-messages branch from 3dc6ee6 to c2e6f33 Compare April 29, 2026 13:40
@github-actions github-actions Bot added type:chore Maintenance, refactoring, tooling type:docs Documentation only labels Apr 29, 2026
@vmvarela vmvarela merged commit b402888 into master Apr 29, 2026
4 checks passed
@vmvarela vmvarela deleted the issue-81/improve-sql-error-messages branch April 29, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:high Must be in the next sprint size:s Small — 1 to 4 hours type:chore Maintenance, refactoring, tooling type:docs Documentation only type:feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve SQL error messages with column and row context

1 participant