emit Error objects from socket 'error' events

main tightened the socket error contract to pass an Error (see
types/modules/networking.d.ts, which documents the reason as
`error.message`); the epoxy rewrite still emitted a bare string,
matching the older `(reason: string)` declaration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Toshit Chawda
2026-08-10 18:54:17 -04:00
committed by Neal Shah
co-authored by Claude Opus 5
parent 6b23e7d7ed
commit 29456a24d5
@@ -19,12 +19,12 @@ function normalizeWriteData (data) {
throw new Error('Invalid data type (not TypedArray, ArrayBuffer or String).');
}
function normalizeErrorReason (reason) {
function normalizeError (reason) {
if ( reason instanceof Error ) {
return reason.message;
return reason;
}
return String(reason);
return new Error(String(reason));
}
export class PSocket extends EventListener {
@@ -236,7 +236,7 @@ export class PSocket extends EventListener {
return;
}
this.emit('error', normalizeErrorReason(reason));
this.emit('error', normalizeError(reason));
this.#closing = true;
void this.#closeStreams(true);
}