Missing error bubbling when Viem throws in watchReadContract
Is there an existing issue for this?
- [X] I have searched the existing issues
Package Version
1.4.2
Current Behavior
An error is logged and thrown by Viem subsequently crashing the app.
Expected Behavior
An error is logged and thrown by Viem before bubbling up to the Wagmi call context. This allows the error to be handled.
Steps To Reproduce
In the following example, if there is no contract at the specified tokenAddress then an error is logged and the app crashes but the catch has no effect.
try {
watchReadContract(
{
address: tokenAddress,
abi: MyToken__factory.abi,
functionName: 'allowance',
args: [ownerAddress, spenderAddress],
chainId: appChainId,
listenToBlock: true,
},
(newData) => {
// Update data only if it has changed
if (serialize(data) !== serialize(newData)) setData(newData);
}
);
} catch (err: any) {
console.error(err.message);
}
Link to Minimal Reproducible Example (StackBlitz, CodeSandbox, GitHub repo etc.)
No response
Anything else?
Potential solutions include:
- returning a catchable promise
- catching the Viem error that can arise in readContract and bubbling it up
Thanks for reporting. This issue is temporarily closed due to lack of information. Please provide a minimal reproducible example (can use new.wagmi.sh) and reopen this issue.
This issue has been locked since it has been closed for more than 14 days.
If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest wagmi version. If you have any other comments you can create a new discussion.