Err.of
Gives the custom errors that a set of calls declares, each once.
import { Abi, Err, Fn, type Address, type Hex, type _ } from "@ethect/core";
class InsufficientAllowance extends Err.make("ERC20InsufficientAllowance", { spender: Abi.address, allowance: Abi.uint256, needed: Abi.uint256,}) {}class ExceededMaxDeposit extends Err.make("ERC4626ExceededMaxDeposit", { receiver: Abi.address, assets: Abi.uint256, max: Abi.uint256,}) {}
const approve = Fn.nonpayable<[spender: _, amount: _]>()("approve", { inputs: [Abi.address, Abi.uint256],});const deposit = Fn.nonpayable<[assets: _, receiver: _]>()("deposit", { inputs: [Abi.uint256, Abi.address], errors: [InsufficientAllowance, ExceededMaxDeposit],});
declare const usdc: Address.Address;declare const vault: Address.Address;declare const me: Address.Address;
const reasonOf = (data: Hex.Hex) => { const calls = [approve.at(usdc)(vault, 100n), deposit.at(vault)(100n, me)]; // [InsufficientAllowance, ExceededMaxDeposit] const errors = Err.of(calls); // InsufficientAllowance | ExceededMaxDeposit | Revert.Revert return Err.decode(errors, data);};A transaction that reverted can be any of its calls. Err.of gathers what the revert may be,
for Err.decode and for the errors of a wait.
Returns
Section titled “Returns”ReadonlyArray<new (value: any) => E>
The error classes, in the order the calls declare them. E is the union of the errors of the
calls.
Parameters
Section titled “Parameters”- Type:
ReadonlyArray<Call.Call<any, any>>
The calls. They may be of different functions, with different errors.
Behavior
Section titled “Behavior”- An error is given once, however many of the calls declare it.
- A call reached through a
Contractdeclares the errors of the contract beside those of its function. - A raw call declares none. Neither does a function defined without
errors. - Nothing is encoded or sent. It reads the definitions of the calls.
Ecomes from the type of the calls. Calls typedReadonlyArray<Call.Call<unknown, unknown>>give the same classes, andEisunknown. A function that takes any calls keeps their type with aconsttype parameter: see Calls passed to a function.