Skip to content

Commit

Permalink
Fix null pointer exception in getNodeError check for ExecutionReverte…
Browse files Browse the repository at this point in the history
…dError
  • Loading branch information
Nguyen Anh Tu committed Sep 25, 2024
1 parent 183811c commit 26107f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/khaki-onions-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fix null pointer exception in getNodeError check for ExecutionRevertedError
17 changes: 17 additions & 0 deletions src/utils/errors/getNodeError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ test('ExecutionRevertedError', () => {
`)
})

test('UnknownNodeError check with null cause in error chain', () => {
const error = new TransactionRejectedRpcError(
new Error('null cause', { cause: null }),
)
const result = getNodeError(error, {
account: address.vitalik,
maxFeePerGas: parseGwei('10'),
maxPriorityFeePerGas: parseGwei('11'),
})
expect(result).toMatchInlineSnapshot(`
[UnknownNodeError: An error occurred while executing: Transaction creation failed.
Details: null cause
Version: viem@x.y.z]
`)
})

test('Unknown node error', () => {
const error = new TransactionRejectedRpcError(
new RpcRequestError({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/errors/getNodeError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function getNodeError(
const executionRevertedError =
err instanceof BaseError
? err.walk(
(e) => (e as { code: number }).code === ExecutionRevertedError.code,
(e) => (e as { code: number } | null | undefined)?.code === ExecutionRevertedError.code,
)
: err
if (executionRevertedError instanceof BaseError)
Expand Down

0 comments on commit 26107f8

Please sign in to comment.