You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{ error }=useSimulateContract({address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',abi: wagmiAbi,functionName: 'mint',})// error is of type ContractFunctionRevertedError, rather than MintIsDisabled
Would it make sense for Wagmi to wrap the simulateContract action in a try catch and bubble up the typed error to the hook (caller as suggested by TkDodo here: TanStack/query#5784 (reply in thread))?
If not, is there any cleaner way to return typed errors from Wagmi hook usages? Right now in my custom hook files I am returning an object with the hook result and parsedError right next to it, e.g.
constsimulateBurnOptions=useSimulateContract(...)letsimulateOptionBurnParsedError: undefined|ReturnType<typeofparseCustomError>if(simulateOptionBurn.error){simulateOptionBurnParsedError=parseCustomError(simulateOptionBurn.error)// uses `walk` to try to parse a custom error}return{
simulateOptionBurn,
simulateOptionBurnParsedError,}
which is easy to miss when creating new hooks / consuming errors from existing hooks.
So, is there a more ergonomic way to get typed errors out of the useSimulateContract hooks?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like my CustomErrors to be typed automatically on the return values from useSimulateContract, but I can't due to the way Wagmi is structured.
For a concrete example, using the example abi from the Viem docs describing
walk
,Would it make sense for Wagmi to wrap the
simulateContract
action in a try catch and bubble up the typed error to the hook (caller as suggested by TkDodo here:TanStack/query#5784 (reply in thread))?
If not, is there any cleaner way to return typed errors from Wagmi hook usages? Right now in my custom hook files I am returning an object with the hook result and
parsedError
right next to it, e.g.which is easy to miss when creating new hooks / consuming errors from existing hooks.
So, is there a more ergonomic way to get typed errors out of the
useSimulateContract
hooks?Beta Was this translation helpful? Give feedback.
All reactions