You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when I use a bunch of query methods (like q.SelectUnicorns()) and then just do the usual if err!=nil { return err }, then I'll have a hard time figuring out which of those caused the SQL error.
It would be nice to have the option to enable error wrapping under gen.go in the config; tracking down errors within complex services (especially something like a "no rows" error which otherwise has no other context) can be difficult.
I was able to hack together my own solution by enabling gen.go.emit_interface and using GoWrap to create a decorator with a template similar to this:
...
// {{$decorator}} implements {{.Interface.Type}} and wraps errors with the associated query name.
type {{$decorator}} struct{ {{.Interface.Type}} }
{{range $method := .Interface.Methods}}
func (w *{{$decorator}}) {{$method.Declaration}} {
{{$method.ResultsNames}} = w.{{$.Interface.Name}}.{{$method.Call}}
if err != nil {
err = &SqlcError{QueryName: "{{$method.Name}}", wrapped: err}
}
return
}
{{end}}
What do you want to change?
Free unicorns! And...
Currently, when I use a bunch of query methods (like
q.SelectUnicorns()
) and then just do the usualif err!=nil { return err }
, then I'll have a hard time figuring out which of those caused the SQL error.Therefore, I typically do
It would be nice if there was a feature toggle to enable this wrapping right within the generated code.
What database engines need to be changed?
No response
What programming language backends need to be changed?
Go
The text was updated successfully, but these errors were encountered: