Skip to content

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

@oskarlh

Description

@oskarlh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions