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>
This commit is contained in:
Renegade334 2023-10-21 14:53:41 +01:00 committed by GitHub
parent 5b4a51945c
commit 0e0b85b766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}
@ -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' });
}
/**