From b505ef1ab889be8161bb1efb4908e3dfde5bc1c9 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:45:31 +1100 Subject: [PATCH] Raise SignerError instead of propagating AsyncLockError (#109) --- ethers/contract.nim | 3 +-- ethers/signer.nim | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index 13e4213..ac5d87d 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -133,7 +133,7 @@ proc send( function: string, parameters: tuple, overrides = TransactionOverrides() -): Future[?TransactionResponse] {.async: (raises: [AsyncLockError, SignerError, ProviderError, CancelledError]).} = +): Future[?TransactionResponse] {.async: (raises: [SignerError, ProviderError, CancelledError]).} = if signer =? contract.signer: withLock(signer): @@ -279,7 +279,6 @@ func addAsyncPragma(procedure: var NimNode) = newIdentNode("CancelledError"), newIdentNode("ProviderError"), newIdentNode("EthersError"), - newIdentNode("AsyncLockError"), ), ) ), diff --git a/ethers/signer.nim b/ethers/signer.nim index 4471d33..a6aa82f 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -12,7 +12,7 @@ type Signer* = ref object of RootObj populateLock: AsyncLock -template raiseSignerError*(message: string, parent: ref ProviderError = nil) = +template raiseSignerError*(message: string, parent: ref CatchableError = nil) = raise newException(SignerError, message, parent) template convertError(body) = @@ -95,7 +95,10 @@ template withLock*(signer: Signer, body: untyped) = try: body finally: - signer.populateLock.release() + try: + signer.populateLock.release() + except AsyncLockError as e: + raiseSignerError e.msg, e method populateTransaction*( signer: Signer, @@ -151,7 +154,7 @@ method populateTransaction*( method cancelTransaction*( signer: Signer, tx: Transaction -): Future[TransactionResponse] {.base, async: (raises: [SignerError, CancelledError, AsyncLockError, ProviderError]).} = +): Future[TransactionResponse] {.base, async: (raises: [SignerError, CancelledError, ProviderError]).} = # cancels a transaction by sending with a 0-valued transaction to ourselves # with the failed tx's nonce