@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / decodeRevert

Function: decodeRevert()

decodeRevert(caught, context?): ContractRevertError

Defined in: packages/sdk/src/revert.ts:204

Decodes a caught contract failure into a ContractRevertError.

Details

Never throws and never returns undefined: an undecodable revert still produces the typed error, because "the chain rejected this" is useful even when the bytes are a mystery.

  • caught: The value thrown by viem / the transport.
  • context: Which contract and function were called, for the message.
  • Returns: A ContractRevertError — with errorName + args when the revert data matched one of the protocol's custom errors, else reason (a require string) or data (unrecognized bytes) preserved, and caught in cause.

Gotchas

Decodes unconditionally: it does not first check whether the failure IS a revert, so a transport error (timeout, disconnect) passed here comes back as a ContractRevertError with no errorName. Callers inside the SDK use the internal isRevert / toSdkError pair to make that distinction; neither is exported, so a consumer should pass values it already knows to be revert data — which is the usual case when decoding a failed call's own error.

Parameters

caught

unknown

context?

RevertContext = {}

Returns

ContractRevertError