Documentation
¶
Index ¶
Constants ¶
const Unknown = "unknown"
Unknown can be used as the fallback class name of error classification.
Variables ¶
This section is empty.
Functions ¶
func Unwrap ¶ added in v0.0.20
Unwrap returns the result of calling the Unwrap or Cause methods on the error, otherwise it returns error itself.
func Caller(req *http.Request) error { resp, err := http.DefaultClient.Do(req) if err != nil { return errors.WithStack(fmt.Errorf("caller: %w", err)) } ... } if err, is := Unwrap(Caller(req)).(net.Error); is { ... }
It is compatible with github.com/pkg/errors and built-in errors since 1.13.
Types ¶
type Classifier ¶ added in v0.0.29
Classifier provides functionality to classify errors and represents them as a string, e.g. for metrics system.
func (Classifier) Classify ¶ added in v0.0.29
func (classifier Classifier) Classify(err error, fallback string) string
Classify classifies the error and returns its class name.
func (service *Service) Do(ctx context.Context, payload interface{}) { resp, err := service.proxy.Call(ctx, Data{Payload: payload}) if err != nil { service.telemetry.Increment(global.Classifier.Classify(err, errors.Unknown)) ... } ... }
func (Classifier) ClassifyAs ¶ added in v0.0.29
func (classifier Classifier) ClassifyAs(class string, list ...error) Classifier
ClassifyAs unwraps the errors and stores them with the class name.
classifier := make(errors.Classifier). ClassifyAs("network", new(errors.NetworkError)). ClassifyAs("fs", os.ErrExist, os.ErrNotExist)
func (Classifier) Consistent ¶ added in v0.0.29
func (classifier Classifier) Consistent() bool
Consistent checks that different groups don't contain similar errors.
type Message ¶
type Message string
Message represents a textual error.
const ErrInterrupted errors.Message = "operation interrupted" func Action() error { ... } switch err := Action(); err { case ErrInterrupted: http.Error(..., err.Error(), http.StatusRequestTimeout) case ...: http.Error(..., http.StatusInternalServerError) }
type NetworkError ¶ added in v0.0.29
type NetworkError struct{}
NetworkError can check network errors.
func (*NetworkError) Error ¶ added in v0.0.29
func (*NetworkError) Error() string
func (*NetworkError) Is ¶ added in v0.0.29
func (*NetworkError) Is(err error) bool
Is reports whether the error matches network error class.
func (*NetworkError) Temporary ¶ added in v0.0.29
func (*NetworkError) Temporary() bool
func (*NetworkError) Timeout ¶ added in v0.0.29
func (*NetworkError) Timeout() bool
type Recovered ¶ added in v0.0.26
type Recovered interface { error // Cause returns the original cause of panic. Cause() interface{} }
Recovered represents a recovered after panic error.
type RecoveredError ¶ added in v0.0.29
type RecoveredError struct{}
RecoveredError can check recovered errors.
func (*RecoveredError) Cause ¶ added in v0.0.29
func (*RecoveredError) Cause() interface{}
func (*RecoveredError) Error ¶ added in v0.0.29
func (*RecoveredError) Error() string
func (*RecoveredError) Is ¶ added in v0.0.29
func (*RecoveredError) Is(err error) bool
Is reports whether the error matches recovered error class.
type Retriable ¶ added in v0.0.20
Retriable represents a retriable action error.
It is compatible with github.com/kamilsk/retry (v4 and later).
type RetriableError ¶ added in v0.0.29
type RetriableError struct{}
func (*RetriableError) Error ¶ added in v0.0.29
func (*RetriableError) Error() string
func (*RetriableError) Is ¶ added in v0.0.29
func (*RetriableError) Is(err error) bool
Is reports whether the error matches retriable error class.
func (*RetriableError) Retriable ¶ added in v0.0.29
func (*RetriableError) Retriable() bool
type TemporaryError ¶ added in v0.0.29
type TemporaryError struct{}
TemporaryError can check temporary errors.
func (*TemporaryError) Error ¶ added in v0.0.29
func (*TemporaryError) Error() string
func (*TemporaryError) Is ¶ added in v0.0.29
func (*TemporaryError) Is(err error) bool
Is reports whether the error matches temporary error class.
func (*TemporaryError) Temporary ¶ added in v0.0.29
func (*TemporaryError) Temporary() bool
type TimeoutError ¶ added in v0.0.29
type TimeoutError struct{}
TimeoutError can check timeout errors.
func (*TimeoutError) Error ¶ added in v0.0.29
func (*TimeoutError) Error() string
func (*TimeoutError) Is ¶ added in v0.0.29
func (*TimeoutError) Is(err error) bool
Is reports whether the error matches timeout error class.
func (*TimeoutError) Timeout ¶ added in v0.0.29
func (*TimeoutError) Timeout() bool
Directories
¶
Path | Synopsis |
---|---|
internal
|
|
classifier
Package classifier provides a way to classify an occurred error.
|
Package classifier provides a way to classify an occurred error. |