From ddaed51550308eceda3c9a080503cf1fdfac6ac0 Mon Sep 17 00:00:00 2001 From: jxom <7336481+jxom@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:09:42 +1100 Subject: [PATCH] fix: provider rpc error parsing --- .changeset/giant-pillows-wave.md | 5 +++++ src/core/Provider.ts | 2 ++ src/core/_test/Provider.test.ts | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 .changeset/giant-pillows-wave.md diff --git a/.changeset/giant-pillows-wave.md b/.changeset/giant-pillows-wave.md new file mode 100644 index 00000000..8e5d2d5d --- /dev/null +++ b/.changeset/giant-pillows-wave.md @@ -0,0 +1,5 @@ +--- +"ox": patch +--- + +Fixed parsing of Provider RPC errors. diff --git a/src/core/Provider.ts b/src/core/Provider.ts index ff86fc49..c847f0a5 100644 --- a/src/core/Provider.ts +++ b/src/core/Provider.ts @@ -435,6 +435,8 @@ export function parseErrorObject< const errorObject_ = errorObject as RpcResponse.ErrorObject const error = RpcResponse.parseErrorObject(errorObject_) if (error instanceof RpcResponse.InternalError) { + if (!error.data) return error as never + const { code } = error.data as RpcResponse.ErrorObject if (code === DisconnectedError.code) return new DisconnectedError(errorObject_) as never diff --git a/src/core/_test/Provider.test.ts b/src/core/_test/Provider.test.ts index 067cd85b..3cfe3d92 100644 --- a/src/core/_test/Provider.test.ts +++ b/src/core/_test/Provider.test.ts @@ -318,6 +318,24 @@ describe('Provider.from', () => { ) }) + test('behavior: InternalError', async () => { + const provider = Provider.from({ + async request(_) { + throw new RpcResponse.InternalError({ + message: 'foo', + }) + }, + }) + + await expect(() => + provider.request({ + method: 'eth_blockNumber', + }), + ).rejects.toThrowErrorMatchingInlineSnapshot( + '[RpcResponse.InternalError: Internal JSON-RPC error.]', + ) + }) + test('behavior: BaseError (raw)', async () => { const provider = Provider.from({ async request(_) {