Documentation
¶
Overview ¶
Package errtype classifies errors into low-cardinality names for the error.type telemetry attribute. The name never contains error text, which can carry keys, values, or query arguments. Context cancellation classes win over owner-supplied sentinels; otherwise callers receive a matched name or the innermost Go type, never Error().
Example: class := errtype.Of(context.DeadlineExceeded); fmt.Println(class)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Of ¶
Of returns the name of err's class: the Name of the first matching sentinel in known (after the context errors), otherwise the Go type of the innermost error in its Unwrap chain, such as "*pgconn.PgError". It returns "" for a nil err. It reads error chains synchronously; custom Is and Unwrap implementations must obey the ordinary errors package's contracts.
Example: fmt.Println(errtype.Of(fmt.Errorf("receive: %w", context.Canceled)))
Types ¶
type Sentinel ¶
type Sentinel struct {
// Err is the error to match.
// Example: known := errtype.Sentinel{Err: context.Canceled, Name: "canceled"}; _ = known
Err error
// Name is the value reported when Err matches.
// Example: known := errtype.Sentinel{Err: context.Canceled, Name: "canceled"}; fmt.Println(known.Name)
Name string
}
Sentinel names an error that callers match with errors.Is. Names must be static, bounded classifications, not interpolated error text. Of checks supplied entries in order after the common context errors.
missing := errors.New("object missing")
class := errtype.Of(missing, errtype.Sentinel{Err: missing, Name: "storage.ErrNotFound"})
fmt.Println(class)