Skip to content

Commit

Permalink
barriers: reveal more safe details about the masked error
Browse files Browse the repository at this point in the history
This commit extracts more safe details for the error hidden behind a
barrier. It achieves this using the new `SafeFormatError()` API via
the `redact` package.

As a side effect, this guarantees that a sentry report for a
barrier (including, but not limited to, assertion failures constructed
with errors.NewAssertionErrorWithWrappedErrf) now always spells out
the type of the error behind the barrier. It also includes any
safe-for-reporting strings that the hidden error object would report
when printed out via `%+v`.

Note that this patch is a band-aid: this is really adding more
complexity to the `SafeDetails()` API, which is arguably somewhat
obsolete now that the `errors` and `redact` packages collaborate to
extract safe strings. However, there is some marginal utility
remaining, in the particular case of an error object transported over
the wire where the target server doesn't know how to decode the error
behind the barrier; in this case, the approach taken here ensures that
a modicum of reportable structure is still included.
  • Loading branch information
knz committed Mar 4, 2022
1 parent 7261bff commit 7d46ef1
Show file tree
Hide file tree
Showing 11 changed files with 706 additions and 36 deletions.
2 changes: 2 additions & 0 deletions barriers/barriers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/redact"
"github.com/gogo/protobuf/proto"
)

Expand Down Expand Up @@ -88,6 +89,7 @@ func (e *barrierError) SafeDetails() []string {
sd := errbase.GetSafeDetails(err)
details = sd.Fill(details)
}
details = append(details, redact.Sprintf("masked error: %+v", e.maskedErr).Redact().StripMarkers())
return details
}

Expand Down
46 changes: 40 additions & 6 deletions fmttests/testdata/format/wrap-fmt
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,18 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *barr
<path>:<lineno>: ×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
×
×
×
Error types: (1) *fmttests.errFmt
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
Expand Down Expand Up @@ -324,12 +333,20 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *erru
×: ×
×
--
*barriers.barrierError
*errutil.withPrefix: assertmsg: × (1)
*barriers.barrierError: masked error: × (1)
*errutil.withPrefix: assertmsg: × (2)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
×
×
×
Error types: (1) *fmttests.errFmt
== Extra "2: details"
assertmsg: ×
×
== Extra "error types"
Expand Down Expand Up @@ -440,7 +457,16 @@ Error types: (1) *barriers.barrierError
×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
×
×
×
Error types: (1) *fmttests.errFmt
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
== Exception 1 (Module: "error domain: <none>")
Expand Down Expand Up @@ -1528,10 +1554,18 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
×
×
--
*barriers.barrierError
*domains.withDomain: error domain: pkg <path> (1)
*barriers.barrierError: masked error: × (1)
*domains.withDomain: error domain: pkg <path> (2)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
×
×
×
Error types: (1) *fmttests.errFmt
== Extra "2: details"
error domain: pkg <path>
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
Expand Down
46 changes: 40 additions & 6 deletions fmttests/testdata/format/wrap-fmt-via-network
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,18 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *ba
<path>:<lineno>: ×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ×
| ×
|
| (opaque error leaf)
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
Error types: (1) *errbase.opaqueLeaf
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
Expand Down Expand Up @@ -394,12 +403,20 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *er
×: ×
×
--
*barriers.barrierError
*errutil.withPrefix: assertmsg: × (1)
*barriers.barrierError: masked error: × (1)
*errutil.withPrefix: assertmsg: × (2)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ×
| ×
|
| (opaque error leaf)
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
Error types: (1) *errbase.opaqueLeaf
== Extra "2: details"
assertmsg: ×
×
== Extra "error types"
Expand Down Expand Up @@ -527,7 +544,16 @@ Error types: (1) *barriers.barrierError
×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ×
| ×
|
| (opaque error leaf)
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
Error types: (1) *errbase.opaqueLeaf
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
== Exception 1 (Module: "error domain: <none>")
Expand Down Expand Up @@ -1965,10 +1991,18 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
×
×
--
*barriers.barrierError
*domains.withDomain: error domain: pkg <path> (1)
*barriers.barrierError: masked error: × (1)
*domains.withDomain: error domain: pkg <path> (2)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ×
| ×
|
| (opaque error leaf)
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
Error types: (1) *errbase.opaqueLeaf
== Extra "2: details"
error domain: pkg <path>
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
Expand Down
34 changes: 28 additions & 6 deletions fmttests/testdata/format/wrap-goerr
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,15 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *barr
<path>:<lineno>: ×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
Expand Down Expand Up @@ -312,12 +318,17 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *erru
×: ×
×
--
*barriers.barrierError
*errutil.withPrefix: assertmsg: × (1)
*barriers.barrierError: masked error: × (1)
*errutil.withPrefix: assertmsg: × (2)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "2: details"
assertmsg: ×
×
== Extra "error types"
Expand Down Expand Up @@ -422,7 +433,13 @@ Error types: (1) *barriers.barrierError
×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
== Exception 1 (Module: "error domain: <none>")
Expand Down Expand Up @@ -1422,10 +1439,15 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
×
×
--
*barriers.barrierError
*domains.withDomain: error domain: pkg <path> (1)
*barriers.barrierError: masked error: × (1)
*domains.withDomain: error domain: pkg <path> (2)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "2: details"
error domain: pkg <path>
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
Expand Down
34 changes: 28 additions & 6 deletions fmttests/testdata/format/wrap-goerr-via-network
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,15 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *ba
<path>:<lineno>: ×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
Expand Down Expand Up @@ -350,12 +356,17 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *er
×: ×
×
--
*barriers.barrierError
*errutil.withPrefix: assertmsg: × (1)
*barriers.barrierError: masked error: × (1)
*errutil.withPrefix: assertmsg: × (2)
<path>:<lineno>: *withstack.withStack (top exception)
*assert.withAssertionFailure
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "2: details"
assertmsg: ×
×
== Extra "error types"
Expand Down Expand Up @@ -461,7 +472,13 @@ Error types: (1) *barriers.barrierError
×
×
--
*barriers.barrierError
*barriers.barrierError: masked error: × (1)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
== Exception 1 (Module: "error domain: <none>")
Expand Down Expand Up @@ -1613,10 +1630,15 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
×
×
--
*barriers.barrierError
*domains.withDomain: error domain: pkg <path> (1)
*barriers.barrierError: masked error: × (1)
*domains.withDomain: error domain: pkg <path> (2)
(check the extra data payloads)
== Extra "1: details"
masked error: ×
(1) ××
×
Error types: (1) *errors.errorString
== Extra "2: details"
error domain: pkg <path>
== Extra "error types"
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
Expand Down
Loading

0 comments on commit 7d46ef1

Please sign in to comment.