From 0d4a0d2c2ce8d2519cbb9a5f502f635b77fdf989 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 2 Apr 2026 12:48:09 -0700 Subject: [PATCH] fix: initialize RpcResult before try block to match Python implementation Previously, if this.serialize() threw an exception, result would be undefined when passed to createErrorResult. This fix brings TypeScript in sync with the Python rpc.py implementation which already initializes result before the try block. --- server/src/rpc.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/server/src/rpc.ts b/server/src/rpc.ts index 344fc02cb..9e481aead 100644 --- a/server/src/rpc.ts +++ b/server/src/rpc.ts @@ -41,7 +41,7 @@ export interface RpcApply extends RpcMessage { id: string | undefined; proxyId: string; args: any[]; - method: string; + method?: string; oneway?: boolean; } @@ -63,7 +63,7 @@ interface RpcRemoteProxyValue { __remote_proxy_finalizer_id: string | undefined; __remote_constructor_name: string; __remote_proxy_props: any; - __remote_proxy_oneway_methods: string[]; + __remote_proxy_oneway_methods?: string[]; __serialized_value?: any; } @@ -74,7 +74,7 @@ interface RpcLocalProxyValue { interface Deferred { resolve: (value: any) => void; reject: (e: Error) => void; - method: string; + method: string | undefined; } export interface PrimitiveProxyHandler extends ProxyHandler { @@ -278,7 +278,7 @@ interface LocalProxiedEntry { interface ErrorType { name: string; - message: string; + message?: string; stack?: string; } @@ -308,7 +308,7 @@ export class RpcPeer { static readonly finalizerIdSymbol = Symbol('rpcFinalizerId'); static remotesCollected = 0; static remotesCreated = 0; - static activeRpcPeer: RpcPeer; + static activeRpcPeer: RpcPeer | undefined; static isRpcProxy(value: any) { return !!value?.[RpcPeer.PROPERTY_PROXY_ID]; @@ -720,13 +720,12 @@ export class RpcPeer { case 'param': { const rpcParam = message as RpcParam; const serializationContext: any = {}; - let result: RpcResult; + const result: RpcResult = { + type: 'result', + id: rpcParam.id, + }; try { - result = { - type: 'result', - id: rpcParam.id, - result: this.serialize(this.params[rpcParam.param], serializationContext) - }; + result.result = this.serialize(this.params[rpcParam.param], serializationContext); } catch (e) { // console.error('failure', rpcApply.method, e);