Skip to content

Commit

Permalink
sql/schemachanger/scbuild: minor cleanup
Browse files Browse the repository at this point in the history
Improves the error handling a tad to make runtime errors and assertion failure.
Fixes a typo. Improves testing output.

Release note: None
  • Loading branch information
ajwerner committed Jul 10, 2022
1 parent 6374bd8 commit 6ea2cce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions pkg/sql/schemachanger/scbuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package scbuild

import (
"context"
"runtime"

"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
Expand Down Expand Up @@ -62,12 +63,18 @@ func Build(
SchemaFeatureChecker: dependencies.FeatureChecker(),
}
defer func() {
if recErr := recover(); recErr != nil {
if errObj, ok := recErr.(error); ok {
err = errObj
} else {
err = errors.Errorf("unexpected error encountered while building schema change plan %s", recErr)
}
switch recErr := recover().(type) {
case nil:
// No error.
case runtime.Error:
err = errors.WithAssertionFailure(recErr)
case error:
err = recErr
default:
err = errors.AssertionFailedf(
"unexpected error encountered while building schema change plan %s",
recErr,
)
}
}()
scbuildstmt.Process(b, an.GetStatement())
Expand All @@ -83,7 +90,7 @@ func Build(
for _, e := range bs.output {
if e.metadata.Size() == 0 {
// Exclude targets which weren't explicitly set.
// Explicity-set targets have non-zero values in the target metadata.
// Explicitly-set targets have non-zero values in the target metadata.
continue
}
ts.Targets = append(ts.Targets, scpb.MakeTarget(e.target, e.element, &e.metadata))
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/schemachanger/scbuild/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func run(
var tableID descpb.ID
tdb.QueryRow(t, fmt.Sprintf(`SELECT '%s'::REGCLASS::INT`, tableName)).Scan(&tableID)
if tableID == 0 {
t.Fatalf("failed to read ID of new table %s", tableName)
d.Fatalf(t, "failed to read ID of new table %s", tableName)
}
t.Logf("created relation with id %d", tableID)
}
Expand All @@ -142,7 +142,7 @@ func run(
require.NoError(t, err)
for i := range stmts {
output, err = scbuild.Build(ctx, deps, output, stmts[i].AST)
require.NoErrorf(t, err, "%s", stmts[i].SQL)
require.NoErrorf(t, err, "%s: %s", d.Pos, stmts[i].SQL)
}
})
return marshalState(t, output)
Expand Down

0 comments on commit 6ea2cce

Please sign in to comment.