MCPcopy
hub / github.com/gogf/gf / Code

Function Code

errors/gerror/gerror_api_code.go:117–128  ·  view source on GitHub ↗

Code returns the error code of `current error`. It returns `CodeNil` if it has no error code neither it does not implement interface Code.

(err error)

Source from the content-addressed store, hash-verified

115// Code returns the error code of `current error`.
116// It returns `CodeNil` if it has no error code neither it does not implement interface Code.
117func Code(err error) gcode.Code {
118 if err == nil {
119 return gcode.CodeNil
120 }
121 if e, ok := err.(ICode); ok {
122 return e.Code()
123 }
124 if e, ok := err.(IUnwrap); ok {
125 return Code(e.Unwrap())
126 }
127 return gcode.CodeNil
128}
129
130// HasCode checks and reports whether `err` has `code` in its chaining errors.
131func HasCode(err error, code gcode.Code) bool {

Callers 15

handleErrorLogMethod · 0.92
UnaryErrorMethod · 0.92
GetWithEnvMethod · 0.92
GetWithCmdMethod · 0.92
GetEffectiveMethod · 0.92
RunWithValueMethod · 0.92
Test_CommandFunction · 0.92
ExampleNewCodeFunction · 0.92
ExampleNewCodefFunction · 0.92
ExampleWrapCodeFunction · 0.92
ExampleWrapCodefFunction · 0.92
ExampleCodeFunction · 0.92

Calls 2

CodeMethod · 0.65
UnwrapMethod · 0.65

Tested by 12

Test_CommandFunction · 0.74
ExampleNewCodeFunction · 0.74
ExampleNewCodefFunction · 0.74
ExampleWrapCodeFunction · 0.74
ExampleWrapCodefFunction · 0.74
ExampleCodeFunction · 0.74
Test_CodeFunction · 0.74
Test_SetCodeFunction · 0.74
Test_Code_WithIUnwrapFunction · 0.74
Test_Error_CodeFunction · 0.74
Test_CodeFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…