mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
chore(WebSocketShard): improve zlib-sync errors (#10808)
* chore(WebSocketShard): improve zlib-sync errors * chore(WebSocketShard): move zlib-sync error numbers to constants file * chore(WebSocketShard): move enum, zlib-sync is lazily loaded --------- Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
@@ -668,10 +668,23 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
||||
this.zLibSyncInflate.push(Buffer.from(decompressable), flush ? zLibSync.Z_SYNC_FLUSH : zLibSync.Z_NO_FLUSH);
|
||||
|
||||
if (this.zLibSyncInflate.err) {
|
||||
this.emit(
|
||||
WebSocketShardEvents.Error,
|
||||
new Error(`${this.zLibSyncInflate.err}${this.zLibSyncInflate.msg ? `: ${this.zLibSyncInflate.msg}` : ''}`),
|
||||
);
|
||||
// Must be here because zlib-sync is lazily loaded
|
||||
const ZlibErrorCodes = {
|
||||
[zLibSync.Z_NEED_DICT]: 'Z_NEED_DICT',
|
||||
[zLibSync.Z_STREAM_END]: 'Z_STREAM_END',
|
||||
[zLibSync.Z_ERRNO]: 'Z_ERRNO',
|
||||
[zLibSync.Z_STREAM_ERROR]: 'Z_STREAM_ERROR',
|
||||
[zLibSync.Z_DATA_ERROR]: 'Z_DATA_ERROR',
|
||||
[zLibSync.Z_MEM_ERROR]: 'Z_MEM_ERROR',
|
||||
[zLibSync.Z_BUF_ERROR]: 'Z_BUF_ERROR',
|
||||
[zLibSync.Z_VERSION_ERROR]: 'Z_VERSION_ERROR',
|
||||
} as const satisfies Record<number, string>;
|
||||
|
||||
// Try to match nodejs zlib errors as much as possible
|
||||
const error: NodeJS.ErrnoException = new Error(this.zLibSyncInflate.msg ?? undefined);
|
||||
error.errno = this.zLibSyncInflate.err;
|
||||
error.code = ZlibErrorCodes[this.zLibSyncInflate.err];
|
||||
this.emit(WebSocketShardEvents.Error, error);
|
||||
}
|
||||
|
||||
if (!flush) {
|
||||
|
||||
Reference in New Issue
Block a user