viem icon indicating copy to clipboard operation
viem copied to clipboard

WebSocket `watchBlocks` with `emitOnBegin: true` does not handle connection errors properly

Open oskarlh opened this issue 10 months ago • 0 comments

Check existing issues

Viem Version

2.24.1

Current Behavior

When

  • you use a PublicClient
  • with the webSocket transport
  • and call watchBlocks with the emitOnBegin option,
  • 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 webSocket transport
  • and call watchBlocks with the emitOnBegin option
  • and you do not have an Internet connection The onError handler is called

Steps To Reproduce

  • Add something to keep the script alive (like a setInterval)
  • Disable your Internet connection.
  • Create a PublicClient
  • with the webSocket transport,
  • call watchBlocks with the emitOnBegin option
  • 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

oskarlh avatar Mar 27 '25 16:03 oskarlh