Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: prevent 'undefined' debug message on intentional shard closure (#…
…9846)

* style: prevent 'undefined' debug message on intentional shard closure

addresses #9594

* refactor(WebSocketManager#destroy): improve debug messaging

cleaner stacktrace format
gracefully closing shards will display an appropriate debug `reason`

* style: unresumable debug messaging

---------

Co-authored-by: Almeida <almeidx@pm.me>
  • Loading branch information
Renegade334 and almeidx committed Oct 21, 2023
1 parent 5b4a519 commit 0e0b85b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/discord.js/src/client/websocket/WebSocketManager.js
Expand Up @@ -258,7 +258,7 @@ class WebSocketManager extends EventEmitter {
* @param {number} id The shard id that disconnected
*/
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
this.debug(GatewayCloseCodes[code], shardId);
this.debug(`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`, shardId);
return;
}

Expand Down Expand Up @@ -324,9 +324,9 @@ class WebSocketManager extends EventEmitter {
async destroy() {
if (this.destroyed) return;
// TODO: Make a util for getting a stack
this.debug(`Manager was destroyed. Called by:\n${new Error().stack}`);
this.debug(Object.assign(new Error(), { name: 'Manager was destroyed:' }).stack);
this.destroyed = true;
await this._ws?.destroy({ code: CloseCodes.Normal });
await this._ws?.destroy({ code: CloseCodes.Normal, reason: 'Manager was destroyed' });
}

/**
Expand Down

0 comments on commit 0e0b85b

Please sign in to comment.