Skip to content

Commit 7d46ef1

Browse files
committed
barriers: reveal more safe details about the masked error
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.
1 parent 7261bff commit 7d46ef1

File tree

11 files changed

+706
-36
lines changed

11 files changed

+706
-36
lines changed

barriers/barriers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020

2121
"github.com/cockroachdb/errors/errbase"
22+
"github.com/cockroachdb/redact"
2223
"github.com/gogo/protobuf/proto"
2324
)
2425

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

fmttests/testdata/format/wrap-fmt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,18 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *barr
137137
<path>:<lineno>: ×
138138
×
139139
--
140-
*barriers.barrierError
140+
*barriers.barrierError: masked error: × (1)
141141
<path>:<lineno>: *withstack.withStack (top exception)
142142
*assert.withAssertionFailure
143+
(check the extra data payloads)
144+
== Extra "1: details"
145+
masked error: ×
146+
(1) ××
147+
×
148+
×
149+
×
150+
×
151+
Error types: (1) *fmttests.errFmt
143152
== Extra "error types"
144153
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
145154
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
@@ -324,12 +333,20 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *erru
324333
×: ×
325334
×
326335
--
327-
*barriers.barrierError
328-
*errutil.withPrefix: assertmsg: × (1)
336+
*barriers.barrierError: masked error: × (1)
337+
*errutil.withPrefix: assertmsg: × (2)
329338
<path>:<lineno>: *withstack.withStack (top exception)
330339
*assert.withAssertionFailure
331340
(check the extra data payloads)
332341
== Extra "1: details"
342+
masked error: ×
343+
(1) ××
344+
×
345+
×
346+
×
347+
×
348+
Error types: (1) *fmttests.errFmt
349+
== Extra "2: details"
333350
assertmsg: ×
334351
×
335352
== Extra "error types"
@@ -440,7 +457,16 @@ Error types: (1) *barriers.barrierError
440457
×
441458
×
442459
--
443-
*barriers.barrierError
460+
*barriers.barrierError: masked error: × (1)
461+
(check the extra data payloads)
462+
== Extra "1: details"
463+
masked error: ×
464+
(1) ××
465+
×
466+
×
467+
×
468+
×
469+
Error types: (1) *fmttests.errFmt
444470
== Extra "error types"
445471
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
446472
== Exception 1 (Module: "error domain: <none>")
@@ -1528,10 +1554,18 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
15281554
×
15291555
×
15301556
--
1531-
*barriers.barrierError
1532-
*domains.withDomain: error domain: pkg <path> (1)
1557+
*barriers.barrierError: masked error: × (1)
1558+
*domains.withDomain: error domain: pkg <path> (2)
15331559
(check the extra data payloads)
15341560
== Extra "1: details"
1561+
masked error: ×
1562+
(1) ××
1563+
×
1564+
×
1565+
×
1566+
×
1567+
Error types: (1) *fmttests.errFmt
1568+
== Extra "2: details"
15351569
error domain: pkg <path>
15361570
== Extra "error types"
15371571
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)

fmttests/testdata/format/wrap-fmt-via-network

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,18 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *ba
172172
<path>:<lineno>: ×
173173
×
174174
--
175-
*barriers.barrierError
175+
*barriers.barrierError: masked error: × (1)
176176
<path>:<lineno>: *withstack.withStack (top exception)
177177
*assert.withAssertionFailure
178+
(check the extra data payloads)
179+
== Extra "1: details"
180+
masked error: ×
181+
(1) ×
182+
| ×
183+
|
184+
| (opaque error leaf)
185+
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
186+
Error types: (1) *errbase.opaqueLeaf
178187
== Extra "error types"
179188
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
180189
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
@@ -394,12 +403,20 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *er
394403
×: ×
395404
×
396405
--
397-
*barriers.barrierError
398-
*errutil.withPrefix: assertmsg: × (1)
406+
*barriers.barrierError: masked error: × (1)
407+
*errutil.withPrefix: assertmsg: × (2)
399408
<path>:<lineno>: *withstack.withStack (top exception)
400409
*assert.withAssertionFailure
401410
(check the extra data payloads)
402411
== Extra "1: details"
412+
masked error: ×
413+
(1) ×
414+
| ×
415+
|
416+
| (opaque error leaf)
417+
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
418+
Error types: (1) *errbase.opaqueLeaf
419+
== Extra "2: details"
403420
assertmsg: ×
404421
×
405422
== Extra "error types"
@@ -527,7 +544,16 @@ Error types: (1) *barriers.barrierError
527544
×
528545
×
529546
--
530-
*barriers.barrierError
547+
*barriers.barrierError: masked error: × (1)
548+
(check the extra data payloads)
549+
== Extra "1: details"
550+
masked error: ×
551+
(1) ×
552+
| ×
553+
|
554+
| (opaque error leaf)
555+
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
556+
Error types: (1) *errbase.opaqueLeaf
531557
== Extra "error types"
532558
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
533559
== Exception 1 (Module: "error domain: <none>")
@@ -1965,10 +1991,18 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
19651991
×
19661992
×
19671993
--
1968-
*barriers.barrierError
1969-
*domains.withDomain: error domain: pkg <path> (1)
1994+
*barriers.barrierError: masked error: × (1)
1995+
*domains.withDomain: error domain: pkg <path> (2)
19701996
(check the extra data payloads)
19711997
== Extra "1: details"
1998+
masked error: ×
1999+
(1) ×
2000+
| ×
2001+
|
2002+
| (opaque error leaf)
2003+
| type name: github.com/cockroachdb/errors/fmttests/*fmttests.errFmt
2004+
Error types: (1) *errbase.opaqueLeaf
2005+
== Extra "2: details"
19722006
error domain: pkg <path>
19732007
== Extra "error types"
19742008
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)

fmttests/testdata/format/wrap-goerr

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *barr
131131
<path>:<lineno>: ×
132132
×
133133
--
134-
*barriers.barrierError
134+
*barriers.barrierError: masked error: × (1)
135135
<path>:<lineno>: *withstack.withStack (top exception)
136136
*assert.withAssertionFailure
137+
(check the extra data payloads)
138+
== Extra "1: details"
139+
masked error: ×
140+
(1) ××
141+
×
142+
Error types: (1) *errors.errorString
137143
== Extra "error types"
138144
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
139145
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
@@ -312,12 +318,17 @@ Error types: (1) *assert.withAssertionFailure (2) *withstack.withStack (3) *erru
312318
×: ×
313319
×
314320
--
315-
*barriers.barrierError
316-
*errutil.withPrefix: assertmsg: × (1)
321+
*barriers.barrierError: masked error: × (1)
322+
*errutil.withPrefix: assertmsg: × (2)
317323
<path>:<lineno>: *withstack.withStack (top exception)
318324
*assert.withAssertionFailure
319325
(check the extra data payloads)
320326
== Extra "1: details"
327+
masked error: ×
328+
(1) ××
329+
×
330+
Error types: (1) *errors.errorString
331+
== Extra "2: details"
321332
assertmsg: ×
322333
×
323334
== Extra "error types"
@@ -422,7 +433,13 @@ Error types: (1) *barriers.barrierError
422433
×
423434
×
424435
--
425-
*barriers.barrierError
436+
*barriers.barrierError: masked error: × (1)
437+
(check the extra data payloads)
438+
== Extra "1: details"
439+
masked error: ×
440+
(1) ××
441+
×
442+
Error types: (1) *errors.errorString
426443
== Extra "error types"
427444
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
428445
== Exception 1 (Module: "error domain: <none>")
@@ -1422,10 +1439,15 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
14221439
×
14231440
×
14241441
--
1425-
*barriers.barrierError
1426-
*domains.withDomain: error domain: pkg <path> (1)
1442+
*barriers.barrierError: masked error: × (1)
1443+
*domains.withDomain: error domain: pkg <path> (2)
14271444
(check the extra data payloads)
14281445
== Extra "1: details"
1446+
masked error: ×
1447+
(1) ××
1448+
×
1449+
Error types: (1) *errors.errorString
1450+
== Extra "2: details"
14291451
error domain: pkg <path>
14301452
== Extra "error types"
14311453
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)

fmttests/testdata/format/wrap-goerr-via-network

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *ba
150150
<path>:<lineno>: ×
151151
×
152152
--
153-
*barriers.barrierError
153+
*barriers.barrierError: masked error: × (1)
154154
<path>:<lineno>: *withstack.withStack (top exception)
155155
*assert.withAssertionFailure
156+
(check the extra data payloads)
157+
== Extra "1: details"
158+
masked error: ×
159+
(1) ××
160+
×
161+
Error types: (1) *errors.errorString
156162
== Extra "error types"
157163
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
158164
github.com/cockroachdb/errors/withstack/*withstack.withStack (*::)
@@ -350,12 +356,17 @@ Error types: (1) *assert.withAssertionFailure (2) *errbase.opaqueWrapper (3) *er
350356
×: ×
351357
×
352358
--
353-
*barriers.barrierError
354-
*errutil.withPrefix: assertmsg: × (1)
359+
*barriers.barrierError: masked error: × (1)
360+
*errutil.withPrefix: assertmsg: × (2)
355361
<path>:<lineno>: *withstack.withStack (top exception)
356362
*assert.withAssertionFailure
357363
(check the extra data payloads)
358364
== Extra "1: details"
365+
masked error: ×
366+
(1) ××
367+
×
368+
Error types: (1) *errors.errorString
369+
== Extra "2: details"
359370
assertmsg: ×
360371
×
361372
== Extra "error types"
@@ -461,7 +472,13 @@ Error types: (1) *barriers.barrierError
461472
×
462473
×
463474
--
464-
*barriers.barrierError
475+
*barriers.barrierError: masked error: × (1)
476+
(check the extra data payloads)
477+
== Extra "1: details"
478+
masked error: ×
479+
(1) ××
480+
×
481+
Error types: (1) *errors.errorString
465482
== Extra "error types"
466483
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)
467484
== Exception 1 (Module: "error domain: <none>")
@@ -1613,10 +1630,15 @@ Error types: (1) *domains.withDomain (2) *barriers.barrierError
16131630
×
16141631
×
16151632
--
1616-
*barriers.barrierError
1617-
*domains.withDomain: error domain: pkg <path> (1)
1633+
*barriers.barrierError: masked error: × (1)
1634+
*domains.withDomain: error domain: pkg <path> (2)
16181635
(check the extra data payloads)
16191636
== Extra "1: details"
1637+
masked error: ×
1638+
(1) ××
1639+
×
1640+
Error types: (1) *errors.errorString
1641+
== Extra "2: details"
16201642
error domain: pkg <path>
16211643
== Extra "error types"
16221644
github.com/cockroachdb/errors/barriers/*barriers.barrierError (*::)

0 commit comments

Comments
 (0)