Skip to content

More Descriptive Error When WebSocket Closes with Code 1006 #4625

@adiwajshing

Description

@adiwajshing

Bug Description

The new WebSocket library is pretty great, but when a WebSocket connection closes without completing the control frame exchange, it spits out an empty message TypeError, which isn't very descriptive of the problem and appears as an error message that accidentally slipped through the deployment. The exact line of code is:

fireEvent('error', this, (type, init) => new ErrorEvent(type, init), {
error: new TypeError(reason)
})

Reproducible By

Haven't written exact steps to reproduce, but it happens occasionally on connection closure.

Expected Behavior

Perhaps a better description of the connection closure in the ErrorEvent? "Connection closed with code: xyz"
Also imo, would be better to use a plain Error rather than a TypeError.

If this is something the team feels would be a good addition, happy to make a PR

Logs & Screenshots

TypeError\n    at #onSocketClose (node:internal/deps/undici/undici:13908:20)\n    at TLSSocket.onSocketClose (node:internal/deps/undici/undici:13611:72)\n    at TLSSocket.emit (node:events:520:35)\n    at node:net:346:12\n    at TCP.done (node:_tls_wrap:649:7)

Environment

Ubuntu 20, NodeJS 24.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions