From a6ba6e65838b39e2488f4a71685a357e5f44f5ed Mon Sep 17 00:00:00 2001 From: Mavis Date: Tue, 2 Jun 2026 23:38:16 +0000 Subject: [PATCH] fix: top-level try/catch around connect() with stack trace The schema fix to use uint32 for status was the right call, but the error persists. The fact that the raw bytes are being printed means the new code IS running, but the error must be coming from somewhere outside the inline try/catch blocks. Wrapping the whole connect() in a safety net so we'll see a stack trace on the next run and can pinpoint the exact line. --- packages/krpc-client/src/client.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/krpc-client/src/client.ts b/packages/krpc-client/src/client.ts index 1d7f6fd..451eeb7 100644 --- a/packages/krpc-client/src/client.ts +++ b/packages/krpc-client/src/client.ts @@ -84,6 +84,19 @@ export class KRPCClient { } async connect(): Promise { + // Wrap EVERYTHING in a top-level try so we always get a clean + // error message (not a buried TypeError from protobufjs + // nested-enum resolution). The specific sub-step failures are + // caught inline for nicer messages, but this top-level guard + // is the safety net. + try { + return await this._connectImpl(); + } catch (e) { + throw new Error(`kRPC connect failed at unknown step: ${formatErr(e)} (stack: ${e instanceof Error ? e.stack : 'n/a'})`); + } + } + + private async _connectImpl(): Promise { // RPC handshake try { this.rpcSocket = await tcpConnect( @@ -173,7 +186,7 @@ export class KRPCClient { // eslint-disable-next-line no-console console.error('[krpc-client] stream loop error:', err); }); - } + } // end _connectImpl isConnected(): boolean { return this.rpcSocket !== null && this.streamSocket !== null && !this.closed;