Skip to content

Commit

Permalink
Merge pull request #104881 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1-104813

release-23.1: scrun: don't include plan details for pgerrors
  • Loading branch information
rafiss authored Jun 14, 2023
2 parents 06272bf + a822f8a commit ccb95c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/hash_sharded_index
Original file line number Diff line number Diff line change
Expand Up @@ -1086,3 +1086,11 @@ SELECT c0 FROM t103755 WHERE c0 < 0 OR (c0 IN (VALUES (2)) AND c1 IN (6,8,9)) OR
----
-20
-10

statement ok
CREATE TABLE t104484 (c0 VARBIT(10) AS (B'1') STORED)

# We use '$' to match the end of the error text, since we want to assert
# that the error does not include the schema plan details.
statement error cannot create a sharded index on a computed column$
CREATE INDEX ON t104484(c0 DESC) USING HASH
9 changes: 9 additions & 0 deletions pkg/sql/schemachanger/scerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ func HasSchemaChangerUserError(err error) bool {
return errors.HasType(err, (*schemaChangerUserError)(nil))
}

// UnwrapSchemaChangerUserError returns the cause of a schemaChangerUserError,
// or nil if the error is not a schemaChangerUserError.
func UnwrapSchemaChangerUserError(err error) error {
if scUserError := (*schemaChangerUserError)(nil); errors.As(err, &scUserError) {
return scUserError.err
}
return nil
}

func (e *schemaChangerUserError) Error() string {
return fmt.Sprintf("schema change operation encountered an error: %s", e.err.Error())
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/schemachanger/scrun/scrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ func executeStage(
// cancelation.
if !errors.HasType(err, (*kvpb.TransactionRetryWithProtoRefreshError)(nil)) &&
!errors.Is(err, context.Canceled) &&
!scerrors.HasSchemaChangerUserError(err) {
!scerrors.HasSchemaChangerUserError(err) &&
!pgerror.HasCandidateCode(err) {
err = p.DecorateErrorWithPlanDetails(err)
}
// Certain errors are aimed to be user consumable and should never be
// wrapped.
if scerrors.HasSchemaChangerUserError(err) {
return errors.Unwrap(err)
if userError := scerrors.UnwrapSchemaChangerUserError(err); userError != nil {
return userError
}
return errors.Wrapf(err, "error executing %s", stage)
}
Expand Down

0 comments on commit ccb95c8

Please sign in to comment.