ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Did the 'error' event listener get removed in v6, like provider.on('error', () => {})?

Open crycime opened this issue 2 years ago • 13 comments

Ethers Version

6.2.3

Search Terms

No response

Describe the Problem

Did the 'error' event listener get removed in v6, like provider.on('error', () => {})?

Code Snippet

await provider.on('error', (error) => {
      this.logger.error(`Connection error for chainId ${chainId}. Reconnecting...`, error);
      setTimeout(() => this.setupProviderEvents(provider, chainId), 1000);
    });

Contract ABI

No response

Errors

unhandledRejection TypeError: unknown ProviderEvent (argument="event", value="error", code=INVALID_ARGUMENT, version=6.3.0)

Environment

No response

Environment (Other)

No response

crycime avatar Apr 12 '23 08:04 crycime

This seems to be similar and / or related to https://github.com/ethers-io/ethers.js/issues/3952

mpsq avatar Apr 13 '23 08:04 mpsq

@ricmoo what happened to ProviderEvents? they seem all gone... (same behavior with 6.3.0)

image

image

0xSidius avatar Apr 15 '23 16:04 0xSidius

This will be added in the next minor version. I'm currently trying to figure out the best way to abstract all the possible ways things can go wrong, so an extendable type can be provided for future internal errors.

ricmoo avatar Apr 15 '23 17:04 ricmoo

This will be added in the next minor version. I'm currently trying to figure out the best way to abstract all the possible ways things can go wrong, so an extendable type can be provided for future internal errors.

Thank you, any workaround meanwhile? use window.ethereum.on?

0xSidius avatar Apr 16 '23 09:04 0xSidius

Is there any update about this problem? I am still facing same issue.

MarinBarac avatar May 10 '23 09:05 MarinBarac

It’s fixed in main, but not published yet. There are two small issues I want to include in the minor bump that fixes this. Should be published on npm soon.

ricmoo avatar May 10 '23 10:05 ricmoo

These hidden errors are a real showstopper, is there anything I can help you with so that the release can be published? 🙂

I'm also concerned about this "error handling" for listeners, both for the high-level api and the low-level api:

https://github.com/ethers-io/ethers.js/blob/13593809bd61ef24c01d79de82563540d77098db/src.ts/contract/contract.ts#L583

https://github.com/ethers-io/ethers.js/blob/13593809bd61ef24c01d79de82563540d77098db/src.ts/providers/abstract-provider.ts#L1188

And especially this: https://github.com/ethers-io/ethers.js/blob/13593809bd61ef24c01d79de82563540d77098db/src.ts/providers/subscriber-filterid.ts#L97

I simulate a serious problem by restarting my hardhat test network. Then the whole application gets stuck and there is no way to recover from this bogus state:

@TODO TypeError: results is not iterable
    at FilterIdEventSubscriber._emitResults (/Users/xxx/node_modules/ethers/src.ts/providers/subscriber-filterid.ts:159:30)
    at FilterIdEventSubscriber.#poll (/Users/xxx/node_modules/ethers/src.ts/providers/subscriber-filterid.ts:96:24)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Errors are silently catched everywhere and there is also no global error event listener that could be used to reset the connection.

hans-crypto avatar May 16 '23 10:05 hans-crypto

Added in v6.4.0.

Thanks! :)

ricmoo avatar May 20 '23 22:05 ricmoo

Event after updating to v6.4.0 the issue is still there

hedgehog-millenium avatar Jun 02 '23 05:06 hedgehog-millenium

I’ll look into this in the morning.

ricmoo avatar Jun 02 '23 05:06 ricmoo

Is this still pending?

travisbotello avatar Dec 28 '23 15:12 travisbotello

Did you fix?

zekeluo avatar Mar 23 '24 06:03 zekeluo