Skip to main content

ContractError

Derive Macro ContractError 

Source
#[derive(ContractError)]
{
    // Attributes available to this derive:
    #[error_code]
    #[error_domain]
    #[canonical]
    #[contract_error]
}
Expand description

#[derive(ContractError)] — wire a typed Rust error enum into the PRD #1536 RFC 9457 envelope.

Per-variant attributes:

  • #[error_code("INSUFFICIENT_FUNDS")] (required)
  • #[error_domain("billing.v1")] (required, or set once on the enum)
  • #[canonical(FailedPrecondition)] (required — one of the 16 ProblemCategory variants)

Generates From<MyError> for Problem (server-side) and TryFrom<Problem> for MyError (client-side); unknown error_code/error_domain pairs round-trip back as the original Problem so callers can still handle them as generic envelopes.

Mark exactly one variant #[contract_error(fallback)] (unit, or a single named field receiving the original Problem) to additionally generate a total From<TransportError> for MyError (gated on the SDK rest-client feature). The generated REST client uses it to reconstruct typed variants from an RFC 9457 response and to route un-reconstructable transport/protocol failures into the fallback variant.