@@ -30,11 +30,30 @@ type opaqueLeaf struct {
3030 details errorspb.EncodedErrorDetails
3131}
3232
33+ // opaqueLeafCauses is used when receiving an unknown multi-cause
34+ // wrapper type. Its important property is that if it is communicated
35+ // back to some network system that _does_ know about the type, the
36+ // original object can be restored. We encode multi-cause errors as
37+ // leaf nodes over the network, in order to support backwards
38+ // compatibility with existing single-cause wrapper messages.
39+ //
40+ // This struct *must* be initialized with a non-nil causes value in
41+ // order to comply with go stdlib expectations for `Unwrap()`.
42+ type opaqueLeafCauses struct {
43+ opaqueLeaf
44+ causes []error
45+ }
46+
3347var _ error = (* opaqueLeaf )(nil )
3448var _ SafeDetailer = (* opaqueLeaf )(nil )
3549var _ fmt.Formatter = (* opaqueLeaf )(nil )
3650var _ SafeFormatter = (* opaqueLeaf )(nil )
3751
52+ var _ error = (* opaqueLeafCauses )(nil )
53+ var _ SafeDetailer = (* opaqueLeafCauses )(nil )
54+ var _ fmt.Formatter = (* opaqueLeafCauses )(nil )
55+ var _ SafeFormatter = (* opaqueLeafCauses )(nil )
56+
3857// opaqueWrapper is used when receiving an unknown wrapper type.
3958// Its important property is that if it is communicated
4059// back to some network system that _does_ know about
@@ -70,8 +89,12 @@ func (e *opaqueWrapper) Unwrap() error { return e.cause }
7089func (e * opaqueLeaf ) SafeDetails () []string { return e .details .ReportablePayload }
7190func (e * opaqueWrapper ) SafeDetails () []string { return e .details .ReportablePayload }
7291
73- func (e * opaqueLeaf ) Format (s fmt.State , verb rune ) { FormatError (e , s , verb ) }
74- func (e * opaqueWrapper ) Format (s fmt.State , verb rune ) { FormatError (e , s , verb ) }
92+ func (e * opaqueLeaf ) Format (s fmt.State , verb rune ) { FormatError (e , s , verb ) }
93+ func (e * opaqueLeafCauses ) Format (s fmt.State , verb rune ) { FormatError (e , s , verb ) }
94+ func (e * opaqueWrapper ) Format (s fmt.State , verb rune ) { FormatError (e , s , verb ) }
95+
96+ // opaqueLeafCauses is a multi-cause wrapper
97+ func (e * opaqueLeafCauses ) Unwrap () []error { return e .causes }
7598
7699func (e * opaqueLeaf ) SafeFormatError (p Printer ) (next error ) {
77100 p .Print (e .msg )
0 commit comments