ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.96k stars 1.85k forks source link

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

Open crycime opened 1 year ago

crycime commented 1 year ago

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

mpsq commented 1 year ago

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

0xSidius commented 1 year ago

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

image

image

ricmoo commented 1 year ago

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.

0xSidius commented 1 year ago

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?

MarinBarac commented 1 year ago

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

ricmoo commented 1 year ago

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.

hans-crypto commented 1 year ago

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.

ricmoo commented 1 year ago

Added in v6.4.0.

Thanks! :)

hedgehog-millenium commented 1 year ago

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

ricmoo commented 1 year ago

I’ll look into this in the morning.

travisbotello commented 10 months ago

Is this still pending?

zekeluo commented 7 months ago

Did you fix?

pbrisson commented 2 months ago

Using v6.13.2 I'm still getting the error. It only seems present using a local hardhat node, so I suspect that "non-iterable results" happens when no transaction is made on the block. That would explain why it won't happen in production as several transactions are available on every new block.