mirror of
https://github.com/status-im/nim-codex.git
synced 2025-03-04 04:10:42 +00:00
* fix(statemachine): do not raise from state.run * fix rebase * fix exception handling in SaleProvingSimulated.prove - re-raise CancelledError - don't return State on CatchableError - expect the Proofs_InvalidProof custom error instead of checking a string * asyncSpawn salesagent.onCancelled This was swallowing a KeyError in one of the tests (fixed in the previous commit) * remove error handling states in asyncstatemachine * revert unneeded changes * formatting * PR feedback, logging updates
36 lines
1.0 KiB
Nim
36 lines
1.0 KiB
Nim
import pkg/metrics
|
|
|
|
import ../../logutils
|
|
import ../../utils/exceptions
|
|
import ../statemachine
|
|
import ./error
|
|
|
|
declareCounter(codex_purchases_cancelled, "codex purchases cancelled")
|
|
|
|
logScope:
|
|
topics = "marketplace purchases cancelled"
|
|
|
|
type PurchaseCancelled* = ref object of PurchaseState
|
|
|
|
method `$`*(state: PurchaseCancelled): string =
|
|
"cancelled"
|
|
|
|
method run*(
|
|
state: PurchaseCancelled, machine: Machine
|
|
): Future[?State] {.async: (raises: []).} =
|
|
codex_purchases_cancelled.inc()
|
|
let purchase = Purchase(machine)
|
|
|
|
try:
|
|
warn "Request cancelled, withdrawing remaining funds",
|
|
requestId = purchase.requestId
|
|
await purchase.market.withdrawFunds(purchase.requestId)
|
|
|
|
let error = newException(Timeout, "Purchase cancelled due to timeout")
|
|
purchase.future.fail(error)
|
|
except CancelledError as e:
|
|
trace "PurchaseCancelled.run was cancelled", error = e.msgDetail
|
|
except CatchableError as e:
|
|
error "Error during PurchaseCancelled.run", error = e.msgDetail
|
|
return some State(PurchaseErrored(error: e))
|