Skip to content

Commit 6df271d

Browse files
committed
scplan: unredact logs for unable to make progress error
We have seen this error in tests and Sentry reports. The details for the error do not show up when logs are redacted, so this change makes the details appear in the AssertionError itself. This also makes stageBuilder implement redact.SafeFormatter so that the error is formatted safely. Release note: None
1 parent ab393bc commit 6df271d

File tree

1 file changed

+17
-8
lines changed
  • pkg/sql/schemachanger/scplan/internal/scstage

1 file changed

+17
-8
lines changed

pkg/sql/schemachanger/scplan/internal/scstage/build.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/screl"
2222
"github.com/cockroachdb/cockroach/pkg/util/iterutil"
2323
"github.com/cockroachdb/errors"
24+
"github.com/cockroachdb/redact"
2425
)
2526

2627
// BuildStages builds the plan's stages for this and all subsequent phases.
@@ -267,9 +268,10 @@ func buildPostCommitStages(bc buildContext, bs buildState) (stages []Stage) {
267268
var trace []string
268269
bs.trace = &trace
269270
sb = bc.makeStageBuilder(bs)
270-
panic(errors.WithDetailf(
271-
errors.AssertionFailedf("unable to make progress"),
272-
"terminal state:\n%s\nrule trace:\n%s", sb, strings.Join(trace, "\n")))
271+
panic(errors.AssertionFailedf(
272+
"unable to make progress\nterminal state:\n%v\nrule trace:\n%s",
273+
sb, redact.SafeString(strings.Join(trace, "\n")),
274+
))
273275
}
274276
build(sb)
275277
}
@@ -726,15 +728,22 @@ func (sb stageBuilder) hasAnyNonRevertibleOps() bool {
726728

727729
// String returns a string representation of the stageBuilder.
728730
func (sb stageBuilder) String() string {
729-
var str strings.Builder
731+
return redact.StringWithoutMarkers(sb)
732+
}
733+
734+
// SafeFormat implements redact.SafeFormatter.
735+
func (sb stageBuilder) SafeFormat(p redact.SafePrinter, verb rune) {
730736
for _, t := range sb.current {
731-
str.WriteString(" - ")
732-
str.WriteString(screl.NodeString(t.n))
733-
str.WriteString("\n")
737+
p.SafeString(" - ")
738+
if err := screl.FormatNode(p, t.n); err != nil {
739+
p.UnsafeString(screl.NodeString(t.n))
740+
}
741+
p.SafeString("\n")
734742
}
735-
return str.String()
736743
}
737744

745+
var _ redact.SafeFormatter = stageBuilder{}
746+
738747
// computeExtraOps generates extra operations to decorate a stage with.
739748
// These are typically job-related.
740749
//

0 commit comments

Comments
 (0)