feat: migrate error handling to terrors for precise error types
#32
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
Currently the codebase uses
thiserror-derived enums for error handling. Each module defines a single large enum (e.g.Errorinactors/client/auth.rswith 9 variants,ConnectError/ClientSignErrorinarbiter-client). Individual functions returnResult<_, Error>but can only produce 2–3 of those variants in practice. Callers are forced to handle impossible variants, and the type system offers no proof that all reachable error cases are covered.Problem
_ => unreachable!()or silent catch-allsConnectErrorvsClientSignError) are created purely to scope error variants — a workaround for the lack of per-function precisionProposal
Migrate to
terrorsand replace module-level error enums withOneOf<(ErrA, ErrB, ...)>structural types.Each function declares exactly the errors it can produce:
Errors narrow as they are handled and widen as they propagate up the call stack — both checked at compile time.
Expected outcomes
Trade-offs to consider
?-based error propagation requires explicit.broaden()calls instead ofFromimpls — more verbose at call sitesSupersetOftrait violations can be hard to readtonic,diesel, and other crates that return their own error types needs adapter layerScope
arbiter-client: replaceConnectError+ClientSignErrorarbiter-server/actors/client/auth: replaceErrorarbiter-server/actors/user_agent/auth: replaceErrorClosed due to issues with warning unused code and difficulty implementing this with stable rust.