Skip to content

fix(sqlbuilder): return build error from selector.statement#737

Open
Solaris-star wants to merge 1 commit into
upper:masterfrom
Solaris-star:fix/708-select-statement-nil-guard
Open

fix(sqlbuilder): return build error from selector.statement#737
Solaris-star wants to merge 1 commit into
upper:masterfrom
Solaris-star:fix/708-select-statement-nil-guard

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

selector.statement() discarded build errors:

sq, _ := sel.build()
return sq.statement()

When build failed (e.g. Select("id").As("alias") without From()), sq was nil and callers like String()/Compile() panicked with a nil pointer dereference instead of a clear error.

Fix

Return (*exql.Statement, error) from selector.statement() (same shape as updater/deleter/inserter) and plumb the error through Compile().

String() still panics on error (existing package convention), but now with the real build error message.

Test plan

  • go test ./internal/sqlbuilder
  • regression: As without From no longer nil-derefs

Fixes #708

selector.statement ignored build errors and dereferenced a nil
selectorQuery, causing a nil pointer panic on invalid chains such as
Select(...).As(...) without From.

Match updater/deleter/inserter: surface the build error from statement
and Compile.

Fixes upper#708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled error in select.go causes a nil pointer dereference

1 participant