Documentation
¶
Index ¶
- func Classify(err error, classifiers ...Classifier) error
- func IsDependencyError(err error) bool
- func IsRetryable(err error) bool
- func IsUserError(err error) bool
- func NewDependencyError(cause error) error
- func NewRetryableDependencyError(cause error) error
- func NewRetryableError(cause error) error
- func NewUserError(cause error) error
- type Classifier
- type Verdict
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Classify ¶
func Classify(err error, classifiers ...Classifier) error
Classify is the single, explicit classification pass. It is intended to be called exactly once per error chain — typically by the consumer immediately after a controller returns — and produces a chain that subsequent IsUserError / IsRetryable / IsDependencyError calls can interpret with simple type checks (no further classifier walks).
Semantics:
- nil in, nil out.
- If err's chain already carries a framework classification (*userError or *infraError anywhere in the chain), returns err unchanged — the chain is already interpretable by IsUserError / IsRetryable / IsDependencyError.
- Otherwise, walks the chain from outermost to innermost, asking each classifier per node. The FIRST non-Unknown verdict wins; the outermost such node determines the wrap. err is wrapped with the framework constructor matching that verdict (User -> NewUserError, InfraRetryable -> NewRetryableError, etc.) and the wrapped error is returned.
- Verdict Infra means "non-retryable infra" — which is already the default behavior for an unwrapped chain, so no wrap is added.
- If no classifier recognises anything, err is returned unchanged.
Implementation: two passes over the chain. Pass 1 is a cheap type check looking for an existing framework wrap and short-circuits if one is found — no classifier is invoked. Pass 2 runs the configured classifiers per node. Walking the chain is cheap relative to a classifier call, so this avoids running classifiers whenever the chain is already classified deeper down.
NOTE: this central classifier model cannot disambiguate errors of the same underlying type produced by different extensions (e.g. a net.OpError from a mysql connection vs the same type from an HTTP caller would both match the mysql classifier here). Resolving that requires per-extension provenance tagging; intentionally deferred.
func IsDependencyError ¶
IsDependencyError reports whether err is or wraps an infra error marked as originating in a downstream dependency, i.e. an error produced by NewDependencyError or NewRetryableDependencyError. Inspects only the framework types in the chain.
func IsRetryable ¶
IsRetryable reports whether err is or wraps an infra error marked retryable, i.e. an error produced by NewRetryableError or NewRetryableDependencyError. Inspects only the framework types in the chain.
func IsUserError ¶
IsUserError reports whether err is or wraps a user error, i.e. an error produced by NewUserError. Inspects only the framework types in the chain.
func NewDependencyError ¶
NewDependencyError creates a non-retryable dependency infra error wrapping the given cause. A dependency error is an error that is caused by a downstream dependency outside the control of the current system, for example an external build system being down.
func NewRetryableDependencyError ¶
NewRetryableDependencyError creates a retryable dependency infra error wrapping the given cause. A retryable dependency error is an error that is caused by a downstream dependency outside the control of the current system, for example an external build system being down.
func NewRetryableError ¶
NewRetryableError creates a retryable infra error wrapping the given cause.
func NewUserError ¶
NewUserError creates a user error wrapping the given cause. A user error is an error that is caused by the user's action or input, for example an invalid input or a merge conflict. User errors are never retryable — only infrastructure errors can be retryable.
Types ¶
type Classifier ¶
Classifier inspects a single error node (not the whole chain) and returns a Verdict. Implementations should return Unknown for nodes they do not recognize so the chain walker can continue down the unwrap chain.
Classifiers must not call errors.As / errors.Is themselves, which would walk the chain and could shadow a classification carried by an outer node (such as a controller's explicit NewUserError wrap). The package-level Classify function owns the walk.
Classifiers are typically stateless; the canonical convention is to expose a package-level singleton value (e.g. mysqlerrs.Classifier) rather than a constructor.
type Verdict ¶
type Verdict int
Verdict is the classification of a single error node, returned by a Classifier. Unknown means the node carries no signal and the chain walker should keep looking; every other value names a terminal classification.
const ( // Unknown means this node carries no classification. The chain walker // will move on to the next node in the unwrap chain. Unknown Verdict = iota // User means the error is caused by the user's input or action (e.g. a // merge conflict or invalid request) and must not be retried. User // Infra means a non-retryable infrastructure failure: something below the // caller broke in a way that retrying will not fix (e.g. a schema or // programmer bug). This is the implicit verdict for an unclassified chain, // so Classify does not add a wrap for it. Infra // InfraRetryable means a transient infrastructure failure that is // expected to succeed on retry (e.g. a deadlock, lock-wait timeout, or // dropped connection). InfraRetryable // InfraDependency means a non-retryable failure originating in a // downstream dependency outside the caller's control (e.g. an external // service rejecting the request). InfraDependency // InfraDependencyRetryable means a transient failure originating in a // downstream dependency (e.g. an external service is briefly unavailable) // that is expected to succeed on retry. InfraDependencyRetryable )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package generic provides an errs.Classifier for errors that are not tied to any particular backend.
|
Package generic provides an errs.Classifier for errors that are not tied to any particular backend. |
|
Package mysql provides an errs.Classifier for errors originating from the go-sql-driver/mysql driver and the standard database/sql + net packages commonly seen when talking to a MySQL backend.
|
Package mysql provides an errs.Classifier for errors originating from the go-sql-driver/mysql driver and the standard database/sql + net packages commonly seen when talking to a MySQL backend. |