Skip to content

Commit

Permalink
fix: nullish reference in getNodeError (#2769)
Browse files Browse the repository at this point in the history
* Fix null pointer exception in getNodeError check for ExecutionRevertedError

* Update khaki-onions-teach.md

---------

Co-authored-by: Nguyen Anh Tu <tunguyen.bhtech@gmail.com>
Co-authored-by: jxom <j@wevm.dev>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 183811c commit ed22d38
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
---

Fixed undefined reference in `getNodeError`.
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 ed22d38

Please sign in to comment.