@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+argswhen the revert data matched one of the protocol's custom errors, elsereason(a require string) ordata(unrecognized bytes) preserved, andcaughtincause.
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 = {}