{"modulePath":"github.com/uber/submitqueue","version":"v0.1.0-dev9","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package errs\n\n## Functions\n\n```go\nfunc IsDependencyError(err error) bool\n```\nIsDependencyError 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.\n\n```go\nfunc IsRetryable(err error) bool\n```\nIsRetryable 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.\n\n```go\nfunc IsUserError(err error) bool\n```\nIsUserError reports whether err is or wraps a user error, i.e. an error produced by NewUserError. Inspects only the framework types in the chain.\n\n```go\nfunc NewDependencyError(cause error) error\n```\nNewDependencyError 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.\n\n```go\nfunc NewRetryableDependencyError(cause error) error\n```\nNewRetryableDependencyError 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.\n\n```go\nfunc NewRetryableError(cause error) error\n```\nNewRetryableError creates a retryable infra error wrapping the given cause.\n\n```go\nfunc NewUserError(cause error) error\n```\nNewUserError 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.\n\n## Types\n\n```go\ntype Classifier interface {\n\tClassify(err error) Verdict\n}\n```\nClassifier 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.\n\nClassifiers 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 classifier-based ErrorProcessor (see NewClassifierProcessor) owns the walk.\n\nClassifiers are typically stateless; the canonical convention is to expose a package-level singleton value (e.g. mysqlerrs.Classifier) rather than a constructor.\n\n```go\ntype ErrorProcessor interface {\n\tProcess(err error) error\n}\n```\nErrorProcessor transforms an error returned by a controller into the error the surrounding transport will react to. It runs exactly once per failing delivery — typically called by the consumer immediately after a controller returns — and the result is what IsRetryable / IsUserError / IsDependencyError will subsequently inspect.\n\nTwo implementations ship in this package:\n\n  - NewClassifierProcessor runs a per-node classifier walk. This preserves controller-attached framework wraps (NewUserError, NewDependencyError, ...) verbatim and only invokes the supplied classifiers when the chain carries no existing framework type. Use it for primary pipeline consumers where controller-driven classification is the source of truth.\n\n  - AlwaysRetryableProcessor unconditionally wraps every non-nil error with NewRetryableError, overriding any inner framework wrap. Use it for narrowly-scoped consumers — typically DLQ reconciliation — that must redeliver on any failure because there is no further dead-letter destination.\n\nSeparating \"decide how an error is interpreted\" from \"decide what to do with the interpreted error\" lets the same consumer implementation host transports with very different retry policies without leaking the policy into each Controller.\n\n```go\nvar AlwaysRetryableProcessor ErrorProcessor = alwaysRetryableProcessor{}\n```\nAlwaysRetryableProcessor classifies every non-nil error as InfraRetryable by wrapping it with NewRetryableError. The wrap is unconditional: an inner \\*userError or non-retryable \\*infraError is overridden because errors.As (used by IsRetryable) matches the outermost \\*infraError first, and that outer wrap is always retryable=true.\n\nSide-effect: an inner \\*infraError carrying dependency=true is masked. The outer wrap is constructed with dependency=false, so IsDependencyError on the result returns false even though the original chain originated in a dependency. This is acceptable for the intended DLQ-reconciliation use case where only IsRetryable drives transport behavior; if dependency provenance ever needs to survive this processor it must be added here explicitly.\n\nPair this only with consumers whose controllers should retry on any returned error. On a primary pipeline consumer this would loop forever on genuine user errors and prevent them from reaching the DLQ.\n\n```go\nfunc NewClassifierProcessor(classifiers ...Classifier) ErrorProcessor\n```\nNewClassifierProcessor returns an ErrorProcessor that runs the supplied classifiers over the chain of any non-nil error.\n\nSemantics of Process on the returned processor:\n\n  - nil in, nil out.\n  - 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.\n  - 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 -\u003e NewUserError, InfraRetryable -\u003e NewRetryableError, etc.) and the wrapped error is returned.\n  - Verdict Infra means \"non-retryable infra\" — which is already the default behavior for an unwrapped chain, so no wrap is added.\n  - If no classifier recognises anything, err is returned unchanged.\n\nImplementation: 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.\n\nPassing no classifiers is valid — the processor will still honour any framework wrap already in the chain and otherwise return err unchanged.\n\nNOTE: 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.\n\n```go\ntype Verdict int\n```\nVerdict 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.\n\n```go\nconst (\n\t// Unknown means this node carries no classification. The chain walker\n\t// will move on to the next node in the unwrap chain.\n\tUnknown Verdict = iota\n\t// User means the error is caused by the user's input or action (e.g. a\n\t// merge conflict or invalid request) and must not be retried.\n\tUser\n\t// Infra means a non-retryable infrastructure failure: something below the\n\t// caller broke in a way that retrying will not fix (e.g. a schema or\n\t// programmer bug). This is the implicit verdict for an unclassified chain,\n\t// so Classify does not add a wrap for it.\n\tInfra\n\t// InfraRetryable means a transient infrastructure failure that is\n\t// expected to succeed on retry (e.g. a deadlock, lock-wait timeout, or\n\t// dropped connection).\n\tInfraRetryable\n\t// InfraDependency means a non-retryable failure originating in a\n\t// downstream dependency outside the caller's control (e.g. an external\n\t// service rejecting the request).\n\tInfraDependency\n\t// InfraDependencyRetryable means a transient failure originating in a\n\t// downstream dependency (e.g. an external service is briefly unavailable)\n\t// that is expected to succeed on retry.\n\tInfraDependencyRetryable\n)\n```\n\n","path":"github.com/uber/submitqueue/core/errs","name":"errs","synopsis":"","isRedistributable":true}
