GetPGCodeInternal retrieves a code for the error. It operates by combining the inner (cause) code and the code at the current level, at each level of cause. - at each level: - if there is a candidate code at that level, that is used; - otherwise, it calls computeDefaultCode(). if the function ret
( err error, computeDefaultCode func(err error) (code pgcode.Code), )
| 59 | // This function should not be used directly. It is only exported |
| 60 | // for use in testing code. Use GetPGCode() instead. |
| 61 | func GetPGCodeInternal( |
| 62 | err error, computeDefaultCode func(err error) (code pgcode.Code), |
| 63 | ) (code pgcode.Code) { |
| 64 | code = pgcode.Uncategorized |
| 65 | if c, ok := err.(*withCandidateCode); ok { |
| 66 | code = pgcode.MakeCode(c.code) |
| 67 | } else if newCode := computeDefaultCode(err); newCode.String() != "" { |
| 68 | code = newCode |
| 69 | } |
| 70 | |
| 71 | if c := errors.UnwrapOnce(err); c != nil { |
| 72 | innerCode := GetPGCodeInternal(c, computeDefaultCode) |
| 73 | code = combineCodes(innerCode, code) |
| 74 | } |
| 75 | |
| 76 | return code |
| 77 | } |
| 78 | |
| 79 | // ComputeDefaultCode looks at the current error object |
| 80 | // (not its causes) and returns: |
no test coverage detected
searching dependent graphs…