Skip to main content

Errors

Each sub-client returns its own error enum, with typed variants for the states you branch on. The umbrella sdk_4mica::Error implements From for every one of them, so a function that mixes operations can use one ?.

Unknown outcomes

A request that has reached the facilitator cannot be called back, and an answer that never arrives does not mean it failed. The SDK reports that case as OutcomeUnknown, never as an ordinary failure, so that a retry loop does not move the same money twice. The SDK returns it when the request was sent and no usable answer came back: a timeout, a dropped connection, an HTTP 5xx or 408, or a response it cannot read. An unpinned .send() never falls back to a self-funded transaction after an unknown outcome. Do not retry it blindly. Look at what the operation would have changed first:
  • Deposit. A second authorization is a second deposit, not a retry. Read the balance with client.account.assets() before you sign again.
  • Withdrawal request. A second request overwrites the first and restarts the grace period. Read withdrawal_request_amount from client.account.assets().
  • Settlement. A second payment or claim reverts after paying gas when the first one went through. Confirm on-chain whether the cycle was settled before you send again.
A refusal is not an unknown outcome. Transport from a facilitator call means the facilitator did not act on the request: the connection failed, or it answered an HTTP 4xx other than 408. Rejected means the facilitator read the request and declined it. Nothing was submitted in either case.
For the wallet’s own transactions, Transport covers both the broadcast and the wait for the receipt. If a .self_funded() or unpinned terminal returns it, the transaction may still be mined. Check the chain before you send it again.

Facilitator refusals

A facilitator refusal carries a machine-readable code, a message, and retryable, which says whether the identical request may succeed later.
  • Withdrawals and settlement return SponsorshipError::Rejected { code, message, retryable } inside Sponsorship(..).
  • Deposits return DepositError::Facilitator { code, message, retryable }, except that sponsorship_unavailable is DepositError::FacilitatorNotConfigured, the same variant as when no facilitator URL is set.
code is passed through verbatim, for example rate_limited or simulation_reverted, so you can branch on a code the SDK does not know. Two allowance errors have their own variants on DepositError and SettlementError:
  • Permit2AllowanceRequired { message, eip2612_nonce }: the facilitator found no Permit2 approval. When eip2612_nonce is present, pin .permit2().sponsor_approval() to sign the approval. When it is absent, the wallet must send approve(PERMIT2, ...) itself.
  • Erc20AllowanceRequired { token, spender, allowance, needed }: the SDK checked the allowance before a self-funded fallback and found it too low. Grant it with the builder’s .self_funded().approve() and retry.

Reverts

A revert the SDK recognizes becomes a typed variant: Any other revert is UnknownRevert { selector, data }, and it carries its reason. When data is a standard Error(string) revert, the error’s Display output is reverted: <reason>. Aave’s numeric reason codes are spelled out, for example reverted: 51 (Aave: supply cap exceeded). A revert that is one of the contracts’ own errors without a variant above prints its name, for example reverted: EscrowUnderflow (selector 0x...). Anything else prints unknown revert (selector 0x...). data holds the raw bytes either way.
Settlement adds SettlementError::RevertedOnChain { tx_hash } for a transaction that was mined and reverted, so gas was spent. On a gasless route, a revert is caught in the facilitator’s simulation and arrives as a refusal with the code simulation_reverted.

Coded refusals

When core refuses a payment or a checkpoint with a stable code, PaymentError has a variant that carries the decoded details. The SDK records core’s clock and the new cycle from these refusals, and the cutoff when the refusal names its own payer. Build a fresh payment with new_payment and it is stamped correctly. Any other refusal from core arrives as PaymentError::Rpc(err), where err.status() and err.code() report the HTTP status and core’s code.

Receipt errors

client.payment.verify_guarantee and verify_guarantee_receipt return these PaymentError variants:

Distinguishing errors

Match on the variants you can act on and pass the rest up.
Every error implements std::error::Error and converts into sdk_4mica::Error, so you can return that umbrella type to handle any SDK failure in one place.

Next steps

Overview

Install the SDK and see the capabilities at a glance.

Client operations

Deposit collateral, sign payments, and settle cleared cycles.