MCPcopy Create free account
hub / github.com/juju/errors / WithType

Function WithType

errortypes.go:105–113  ·  view source on GitHub ↗

WithType is responsible for annotating an already existing error so that it also satisfies that of a ConstError. The resultant error returned should satisfy Is(err, errType). If err is nil then a nil error will also be returned. Now with Go's Is, As and Unwrap support it no longer makes sense to Wr

(err error, errType ConstError)

Source from the content-addressed store, hash-verified

103// WithType aims to solve some of the usefulness of Wrap with the ability to
104// make a pre-existing error also satisfy a ConstError type.
105func WithType(err error, errType ConstError) error {
106 if err == nil {
107 return nil
108 }
109 return &errWithType{
110 error: err,
111 errType: errType,
112 }
113}
114
115// Timeoutf returns an error which satisfies Is(err, Timeout) and the Locationer
116// interface.

Callers 2

TestWithTypeNilMethod · 0.92
TestWithTypeMethod · 0.92

Calls

no outgoing calls

Tested by 2

TestWithTypeNilMethod · 0.74
TestWithTypeMethod · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…