diff --git a/apps/tools/ksp-bridge/src/krpc-adapter.ts b/apps/tools/ksp-bridge/src/krpc-adapter.ts index 4d73f2c..c71ee74 100644 --- a/apps/tools/ksp-bridge/src/krpc-adapter.ts +++ b/apps/tools/ksp-bridge/src/krpc-adapter.ts @@ -64,8 +64,17 @@ export class KRPCAdapter { return; } await this.client.connect(); - const loaded = await loadServices(this.client); - this.services = loaded.services; + try { + const loaded = await loadServices(this.client); + this.services = loaded.services; + } catch (e) { + // loadServices calls client.invoke, which decodes the + // KRPC.GetServices response (a HUGE KRPC.Services message). + // If anything goes wrong decoding that, surface a clear + // error instead of the buried protobufjs TypeError. + const msg = e instanceof Error ? e.message : String(e); + throw new Error(`kRPC loadServices (GetServices decode) failed: ${msg}`); + } } async disconnect(): Promise { diff --git a/packages/krpc-client/src/schema.ts b/packages/krpc-client/src/schema.ts index 9f8773d..5953eb7 100644 --- a/packages/krpc-client/src/schema.ts +++ b/packages/krpc-client/src/schema.ts @@ -204,8 +204,17 @@ const schemaJson = { }, }, Type: { + // The `code` field on Type is a wire-varint enum + // (TypeCode = uint32 under the hood). We model it as a + // plain uint32 to dodge the protobufjs nested-enum + // default-value lookup bug that throws + // "Cannot read properties of null (reading 'code')" + // when decoding a Type message whose code field is + // present. Same fix as ConnectionResponse.status. + // The values stay as a nested TypeCode enum for + // documentation / programmatic lookup (in services.ts). fields: { - code: { type: 'Type.TypeCode', id: 1 }, + code: { type: 'uint32', id: 1 }, service: { type: 'string', id: 2 }, name: { type: 'string', id: 3 }, types: { rule: 'repeated', type: 'Type', id: 4 },