-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: flattening error objects into other errors erases telemetry data and user hints #42510
Copy link
Copy link
Closed
Labels
A-error-handlingError messages, error propagations/annotationsError messages, error propagations/annotationsC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)T-sql-queriesSQL Queries TeamSQL Queries Team
Description
I found this while looking for something else:
func NewInvalidSchemaDefinitionError(err error) error {
return pgerror.New(pgcode.InvalidSchemaDefinition, err.Error())
}By flattening the error with err.Error() this constructor strips the error object of all its details, including stack traces but also user-directed hints, links to documentation issues and telemetry data.
Other examples (non exhaustive):
execute.go: return nil, pgerror.New(pgcode.WrongObjectType, err.Error())
export.go: return nil, pgerror.New(pgcode.InvalidParameterValue, err.Error())
rowexec/hashjoiner.go: err = pgerror.Wrapf(addErr, pgcode.OutOfMemory, "while spilling: %v", err)
set_var.go: return wrapSetVarError("statement_timeout", s, "%v", err)
There are multiple ways to fix it:
- prefer
errors.Wrap[f]when no need to add a pg code - use
pgerror.WithCandidateCodewhen need to add a pg code if there wasn't one already to start with - use
errors.Combineorerrors.WithSecondaryErrorto combine errors together
I am fixing the first example at the top in #42509, but the other cases remain to be fixed.
cc @cockroachdb/sql-execution
Reactions are currently unavailable
Metadata
Metadata
Labels
A-error-handlingError messages, error propagations/annotationsError messages, error propagations/annotationsC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)T-sql-queriesSQL Queries TeamSQL Queries Team