convex-credits

Retries and errors

Stable operation keys prevent duplicate effects.

Every mutation requires an operation key. Keys are unique within a namespace across operation types and account owners.

Use a stable key for one logical operation, such as receipt:123 or job:456:complete. Repeated identical arguments return the original result. Changed arguments with the same key fail with OPERATION_KEY_CONFLICT.

When a request ID comes from a user, include the authenticated owner and operation type in the key: JSON.stringify([owner, "reserve", requestId]). Do not let two owners share a client-chosen key accidentally.

A failed mutation rolls back its operation key too. Correct the failure and retry. Do not recycle successful keys. The component does not automatically expire keys or delete ledger history.

CodeMeaning
INVALID_AMOUNTAmount is not a positive safe integer.
INVALID_IDENTIFIERNamespace, owner, or key is empty or too long.
INSUFFICIENT_CREDITSThe account cannot cover the debit.
BALANCE_OVERFLOWThe result exceeds the safe-integer range.
OPERATION_KEY_CONFLICTThis key already identifies a different request.
CHARGE_NOT_FOUNDThe charge does not exist in this namespace.
CHARGE_RELEASEDA released charge cannot complete.
CHARGE_COMPLETEDA completed charge cannot release. Use refund.
CHARGE_NOT_COMPLETEDRefund requires a completed charge.
REFUND_EXCEEDS_CHARGERefund exceeds the unrefunded amount.
SELF_TRANSFERTransfer source and destination are the same.

Errors use ConvexError with a code field in its data.