Skip to content

Commit

Permalink
sql: ensure SQLSTATE 42710 on secondary errors
Browse files Browse the repository at this point in the history
When creating an object that collides with another, we have to perform
another lookup to get the kind of object that it collided with.

If an error occurs during this second stage, we want the error to
propose SQLSTATE "Duplicate object" (42710) to the client if there is
no pgcode in the error object already.

Release note: None
  • Loading branch information
knz committed Jul 14, 2020
1 parent 161d68e commit b5db9ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/sql/sqlbase/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func NewDatabaseAlreadyExistsError(name string) error {
// when an error occurs while trying to get the colliding object for an
// ObjectAlreadyExistsErr.
func WrapErrorWhileConstructingObjectAlreadyExistsErr(err error) error {
return errors.Wrap(err, "object already exists")
return pgerror.WithCandidateCode(errors.Wrap(err, "object already exists"), pgcode.DuplicateObject)
}

// MakeObjectAlreadyExistsError creates an error for a namespace collision
Expand Down

0 comments on commit b5db9ca

Please sign in to comment.