ComputeDefaultCode looks at the current error object (not its causes) and returns: - the existing code for Error instances - SerializationFailure for roachpb retry errors that can be reported to clients - StatementCompletionUnknown for ambiguous commit errors - InternalError for assertion failures -
(err error)
| 87 | // It is not meant to be used directly - it is only exported |
| 88 | // for use by test code. Use GetPGCode() instead. |
| 89 | func ComputeDefaultCode(err error) pgcode.Code { |
| 90 | switch e := err.(type) { |
| 91 | // If there was already a pgcode in the cause, use that. |
| 92 | case *Error: |
| 93 | return pgcode.MakeCode(e.Code) |
| 94 | // Special roachpb errors get a special code. |
| 95 | case ClientVisibleRetryError: |
| 96 | return pgcode.SerializationFailure |
| 97 | case ClientVisibleAmbiguousError: |
| 98 | return pgcode.StatementCompletionUnknown |
| 99 | } |
| 100 | |
| 101 | if errors.IsAssertionFailure(err) { |
| 102 | return pgcode.Internal |
| 103 | } |
| 104 | if errors.IsUnimplementedError(err) { |
| 105 | return pgcode.FeatureNotSupported |
| 106 | } |
| 107 | return pgcode.Code{} |
| 108 | } |
| 109 | |
| 110 | // ClientVisibleRetryError mirrors kvpb.ClientVisibleRetryError but |
| 111 | // is defined here to avoid an import cycle. |
nothing calls this directly
no test coverage detected
searching dependent graphs…