Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket events: Cannot use 'in' operator to search for 'id' in iAA= #4051

Open
kashirin-dm opened this issue May 15, 2023 · 6 comments
Open
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@kashirin-dm
Copy link

Ethers Version

6.1.3

Search Terms

WebSocketProvider, BSC

Describe the Problem

I'm getting this error when listening to pending transactions or events (I do not know for sure):

TypeError: Cannot use 'in' operator to search for 'id' in iAA=
    at WebSocketProvider._processMessage (/app/node_modules/ethers/src.ts/providers/provider-socket.ts:234:17)
    at WebSocketProvider.websocket.onmessage (/app/node_modules/ethers/src.ts/providers/provider-websocket.ts:55:18)
    at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:199:18)
    at WebSocket.emit (node:events:513:28)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:1137:20)
    at Receiver.emit (node:events:513:28)
    at Receiver.dataMessage (/app/node_modules/ws/lib/receiver.js:528:14)
    at Receiver.getData (/app/node_modules/ws/lib/receiver.js:446:17)
    at Receiver.startLoop (/app/node_modules/ws/lib/receiver.js:148:22)
    at Receiver._write (/app/node_modules/ws/lib/receiver.js:83:10)
[ERROR] 19:09:19 TypeError: Cannot use 'in' operator to search for 'id' in iAA=

Sorry, but I can't give more details.

Code Snippet

myWebsocketProvider.on({ topics: [ethers.id('event snippet')] }, async (event: ethers.Log) => {
    // Do something
}).catch((e) => console.error('fBorrow', e));

myWebsocketProvider.on('pending', async (tx: string) => {
    // Do something
}).catch((e) => console.error('fBorrow', e));

Contract ABI

No response

Errors

No response

Environment

node.js (v12 or newer), Geth, Parity

Environment (Other)

Docker

@kashirin-dm kashirin-dm added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels May 15, 2023
@kashirin-dm
Copy link
Author

kashirin-dm commented May 15, 2023

The problem with the ethers.IpcSocketProvider

@kashirin-dm
Copy link
Author

Maybe the problem is related to WebSockets, but it recurs when I use an IPC provider in isolation, without WebSockets.
Also, I installed the latest version of ethers.js from the repository from the main branch and the problem repeats.

@kashirin-dm
Copy link
Author

I forked the repository and made a hotfix in the src.ts/providers/provider-socket.ts file

if (typeof result === 'object' && 'id' in result) {
    // some code
}

@ricmoo
Copy link
Member

ricmoo commented May 17, 2023

Thanks! I can definitely include that fix too. But I’m curious what it is returning that isn’t an object?

@kashirin-dm
Copy link
Author

I haven't checked to be honest. Most likely undefined or null.

@ricmoo
Copy link
Member

ricmoo commented May 20, 2023

I've added that check to the SocketProvider, in v6.4.0 and emit an error event when the message provided contains nonsense, to assist in debugging if similar problems crop up in the future.

Let me know if you continue having any problems.

Thanks! :)

Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants