(ctx context.Context, enc *errorspb.EncodedWrapper)
| 98 | } |
| 99 | |
| 100 | func decodeWrapper(ctx context.Context, enc *errorspb.EncodedWrapper) error { |
| 101 | // First decode the cause. |
| 102 | cause := DecodeError(ctx, enc.Cause) |
| 103 | |
| 104 | // In case there is a detailed payload, decode it. |
| 105 | var payload proto.Message |
| 106 | if enc.Details.FullDetails != nil { |
| 107 | var d types.DynamicAny |
| 108 | err := types.UnmarshalAny(enc.Details.FullDetails, &d) |
| 109 | if err != nil { |
| 110 | // It's OK if we can't decode. We'll use |
| 111 | // the opaque type below. |
| 112 | warningFn(ctx, "error while unmarshalling wrapper error: %+v", err) |
| 113 | } else { |
| 114 | payload = d.Message |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Do we have a wrapper decoder for this? |
| 119 | typeKey := TypeKey(enc.Details.ErrorTypeMark.FamilyName) |
| 120 | if decoder, ok := decoders[typeKey]; ok { |
| 121 | // Yes, use it. |
| 122 | genErr := decoder(ctx, cause, enc.Message, enc.Details.ReportablePayload, payload) |
| 123 | if genErr != nil { |
| 124 | // Decoding succeeded. Use this. |
| 125 | return genErr |
| 126 | } |
| 127 | // Decoding failed, we'll drop through to opaqueWrapper{} below. |
| 128 | } |
| 129 | |
| 130 | // Otherwise, preserve all details about the original object. |
| 131 | return &opaqueWrapper{ |
| 132 | cause: cause, |
| 133 | prefix: enc.Message, |
| 134 | details: enc.Details, |
| 135 | messageType: MessageType(enc.MessageType), |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // RegisterLeafDecoder can be used to register new leaf error types to |
| 140 | // the library. Registered types will be decoded using their own |
no test coverage detected
searching dependent graphs…