refactor(errs): introduce per-backend Classifier framework#183
Merged
Conversation
|
|
Replaces the implicit context.Canceled handling in IsRetryable with an
explicit single-pass Classify call driven by per-backend classifiers.
Controllers still own classification via the framework constructors
(NewUserError / NewRetryableError / NewDependencyError /
NewRetryableDependencyError); for errors a controller does not wrap,
the consumer now runs errs.Classify(err, classifiers...) once per
failing delivery, and downstream IsRetryable / IsUserError /
IsDependencyError become plain type checks.
errs.Classify walks the chain in two passes: pass 1 short-circuits on
any existing framework wrap so an explicit controller verdict always
wins; pass 2 runs the configured classifiers per node, outermost-first,
and prepends the matching framework wrap.
Adds two starter classifiers:
- core/errs/generic — context.Canceled -> InfraRetryable so graceful
shutdowns nack for redelivery instead of rejecting to DLQ.
- core/errs/mysql — server error numbers, driver.ErrBadConn,
sql.ErrConnDone/TxDone, and net.Error values. The classifier never
returns User; constraint violations stay Infra and must be wrapped
explicitly by the controller when they reflect bad user input.
Wires both into the orchestrator's consumer.New call.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
behinddwalls
reviewed
Jun 3, 2026
behinddwalls
approved these changes
Jun 3, 2026
| // Pass 1 — cheap framework-wrap check. If any node already carries a | ||
| // framework type, the chain is interpretable as-is and classifiers are | ||
| // never invoked. | ||
| for cur := err; cur != nil; cur = errors.Unwrap(cur) { |
Collaborator
There was a problem hiding this comment.
do we expect mutli-errors to work in this case?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements an error classification framework in
core/errs: per-backendClassifierimplementations recognise raw driver/library errors and the consumer runs a singleerrs.Classify(err, classifiers...)pass after each delivery. DownstreamIsRetryable/IsUserError/IsDependencyErrorbecome plain type checks; an explicit framework wrap from a controller always wins over any classifier.errs.Classifierinterface,Verdictenum, anderrs.Classify(two-pass: framework-wrap short-circuit, then classifier walk).core/errs/generic—context.Canceled→ retryable infra.core/errs/mysql— server error numbers,driver.ErrBadConn,sql.ErrConnDone/TxDone,net.Error. Never returnsUser; controllers wrap constraint violations withNewUserErrorexplicitly.consumer.Newwires both classifiers.core/errs/README.mddocuments the framework, adding classifiers, and controller overrides.Test plan
🤖 Generated with Claude Code