wagmi icon indicating copy to clipboard operation
wagmi copied to clipboard

Missing error bubbling when Viem throws in watchReadContract

Open vblackwhale opened this issue 3 years ago • 2 comments

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

vblackwhale avatar Oct 18 '23 01:10 vblackwhale

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.

tmm avatar Nov 06 '23 22:11 tmm

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.

github-actions[bot] avatar Jan 06 '24 00:01 github-actions[bot]