Skip to content

Commit

Permalink
feat: print port in the logged error message after failed WS connec…
Browse files Browse the repository at this point in the history
…tion with `EADDRINUSE` (#19212)
  • Loading branch information
Andarist authored Feb 4, 2025
1 parent 602b373 commit 14027b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ export function createWebSocketServer(
}
handleUpgrade(req, socket as Socket, head, protocol === 'vite-ping')
})
wsHttpServer.on('error', (e: Error & { code: string }) => {
wsHttpServer.on('error', (e: Error & { code: string; port: number }) => {
if (e.code === 'EADDRINUSE') {
config.logger.error(
colors.red(`WebSocket server error: Port is already in use`),
colors.red(
`WebSocket server error: Port ${e.port} is already in use`,
),
{ error: e },
)
} else {
Expand Down Expand Up @@ -301,10 +303,10 @@ export function createWebSocketServer(
}
})

wss.on('error', (e: Error & { code: string }) => {
wss.on('error', (e: Error & { code: string; port: number }) => {
if (e.code === 'EADDRINUSE') {
config.logger.error(
colors.red(`WebSocket server error: Port is already in use`),
colors.red(`WebSocket server error: Port ${e.port} is already in use`),
{ error: e },
)
} else {
Expand Down

0 comments on commit 14027b0

Please sign in to comment.