Skip to content

fix(websocket): polyfill missing ErrorEvent global#371

Merged
yusukebe merged 1 commit into
honojs:mainfrom
otnc:fix/websocket-errorevent-polyfill
Jul 11, 2026
Merged

fix(websocket): polyfill missing ErrorEvent global#371
yusukebe merged 1 commit into
honojs:mainfrom
otnc:fix/websocket-errorevent-polyfill

Conversation

@otnc

@otnc otnc commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Node.js has no global ErrorEvent (unlike Event, MessageEvent, and CloseEvent,
which are already polyfilled/native). When the underlying ws socket emits an
error event, upgradeWebSocket's handler does new ErrorEvent('error', { error }),
which throws a ReferenceError on every supported Node version. That error is caught
and passed to the internal onError fallback instead — so the user's onError
handler passed to upgradeWebSocket is never invoked, and the original error is lost.

This adds an ErrorEvent polyfill following the same pattern as the existing
CloseEvent one, and adds a test that reproduces the bug by emitting a real
error event on the raw socket and asserting the user's onError receives it.

Node.js has no global ErrorEvent, so `new ErrorEvent(...)` threw a
ReferenceError and silently swallowed the user's onError handler.

@yusukebe yusukebe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe

Copy link
Copy Markdown
Member

@otnc

Good catch! Looks good. Thank you!

@yusukebe yusukebe merged commit 912e3fd into honojs:main Jul 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants