Raise SignerError instead of propagating AsyncLockError (#109)

This commit is contained in:
Eric 2025-03-13 14:45:31 +11:00 committed by GitHub
parent d2b11a8657
commit b505ef1ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -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"),
),
)
),

View File

@ -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