websockets / ws

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js
MIT License
21.61k stars 2.42k forks source link

WebSocketServer.address() error needs more context #2200

Closed 00f2ff closed 7 months ago

00f2ff commented 7 months ago

Is there an existing issue for this?

Description

If you create a server like const wss = new WebSocketServer({ noServer: true }); and then call wss.address() in a "connection" listener, the server throws this error: 'The server is operating in "noServer" mode'.

I spent a few hours trying to track down why I couldn't get authentication working in an HTTP upgrade handler, only to discover the real problem was that I had a piece of dead code somewhere else that was causing an error (my error handling destroyed the socket).

It would help if the error thrown in address() could be rewritten as 'Cannot return address. The server is operating in "noServer" mode' or just return null.

ws version

Current

Node.js Version

v18.17.1

System

MacOS Sonoma

Expected result

No response

Actual result

No response

Attachments

No response

lpinca commented 7 months ago

Can you explain why adding "Cannot return address." improves the error message? It is implied that nothing is returned, an error is thrown.

lpinca commented 7 months ago

I'm closing this due to inactivity.