From 34643ffe89c447176100f613a231a69364740c15 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Wed, 26 Jun 2024 00:39:06 +0300 Subject: [PATCH] fix(core): correctly handle rpc_error for methods returning vectors of primitives --- packages/core/src/network/session-connection.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/network/session-connection.ts b/packages/core/src/network/session-connection.ts index 28afbba7..98548f4a 100644 --- a/packages/core/src/network/session-connection.ts +++ b/packages/core/src/network/session-connection.ts @@ -55,6 +55,8 @@ const GZIP_PACKED_ID = 0x3072cfa1 const MSG_CONTAINER_ID = 0x73f1f8dc // rpc_result#f35c6d01 req_msg_id:long result:Object = RpcResult; const RPC_RESULT_ID = 0xf35c6d01 +// rpc_error#2144ca19 error_code:int error_message:string = RpcError; +const RPC_ERROR_ID = 0x2144ca19 // invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; const INVOKE_AFTER_MSG_ID = 0xcb9f372d const INVOKE_AFTER_MSG_SIZE = 12 // 8 (invokeAfterMsg) + 4 (msg_id) @@ -752,11 +754,17 @@ export class SessionConnection extends PersistentConnection { const rpc = msg.rpc - const customReader = this._readerMap._results![rpc.method] + const resultConstructorId = message.peekUint() let result: any - if (customReader) { + const customReader = this._readerMap._results![rpc.method] + + if (resultConstructorId === RPC_ERROR_ID) { + // we need to handle this before anything else because otherwise we might + // try to use customReader on an error which will inevitably fail or break + result = message.object() + } else if (customReader) { result = customReader(message) } else { const objectId = message.uint()