viem
viem copied to clipboard
WebSocket `watchBlocks` with `emitOnBegin: true` does not handle connection errors properly
Check existing issues
- [x] I checked there isn't already an issue for the bug I encountered.
Viem Version
2.24.1
Current Behavior
When
- you use a
PublicClient - with the
webSockettransport - and call
watchBlockswith theemitOnBeginoption, - and you do not have an Internet connection The script crashes with an error logged to console
Expected Behavior
When
- you use a
PublicClient - with the
webSockettransport - and call
watchBlockswith theemitOnBeginoption - and you do not have an Internet connection
The
onErrorhandler is called
Steps To Reproduce
- Add something to keep the script alive (like a setInterval)
- Disable your Internet connection.
- Create a
PublicClient - with the
webSockettransport, - call
watchBlockswith theemitOnBeginoption - Observe that the script stops, with errors logged to stdout
Link to Minimal Reproducible Example
https://github.com/oskarlh/viem-bug
Anything else?
No response