-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(statemachine): do not raise from state.run (#1115)
* 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
- Loading branch information
Showing
30 changed files
with
590 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
import pkg/metrics | ||
|
||
import ../../logutils | ||
import ../../utils/exceptions | ||
import ../statemachine | ||
import ./errorhandling | ||
import ./error | ||
|
||
declareCounter(codex_purchases_cancelled, "codex purchases cancelled") | ||
|
||
logScope: | ||
topics = "marketplace purchases cancelled" | ||
|
||
type PurchaseCancelled* = ref object of ErrorHandlingState | ||
type PurchaseCancelled* = ref object of PurchaseState | ||
|
||
method `$`*(state: PurchaseCancelled): string = | ||
"cancelled" | ||
|
||
method run*(state: PurchaseCancelled, machine: Machine): Future[?State] {.async.} = | ||
method run*( | ||
state: PurchaseCancelled, machine: Machine | ||
): Future[?State] {.async: (raises: []).} = | ||
codex_purchases_cancelled.inc() | ||
let purchase = Purchase(machine) | ||
|
||
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) | ||
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import pkg/metrics | ||
import ../../logutils | ||
import ../../utils/exceptions | ||
import ../statemachine | ||
import ./errorhandling | ||
import ./submitted | ||
import ./error | ||
|
||
declareCounter(codex_purchases_pending, "codex purchases pending") | ||
|
||
type PurchasePending* = ref object of ErrorHandlingState | ||
type PurchasePending* = ref object of PurchaseState | ||
|
||
method `$`*(state: PurchasePending): string = | ||
"pending" | ||
|
||
method run*(state: PurchasePending, machine: Machine): Future[?State] {.async.} = | ||
method run*( | ||
state: PurchasePending, machine: Machine | ||
): Future[?State] {.async: (raises: []).} = | ||
codex_purchases_pending.inc() | ||
let purchase = Purchase(machine) | ||
let request = !purchase.request | ||
await purchase.market.requestStorage(request) | ||
return some State(PurchaseSubmitted()) | ||
try: | ||
let request = !purchase.request | ||
await purchase.market.requestStorage(request) | ||
return some State(PurchaseSubmitted()) | ||
except CancelledError as e: | ||
trace "PurchasePending.run was cancelled", error = e.msgDetail | ||
except CatchableError as e: | ||
error "Error during PurchasePending.run", error = e.msgDetail | ||
return some State(PurchaseErrored(error: e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
import pkg/metrics | ||
import ../../utils/exceptions | ||
import ../../logutils | ||
import ../statemachine | ||
import ./errorhandling | ||
import ./submitted | ||
import ./started | ||
import ./cancelled | ||
import ./finished | ||
import ./failed | ||
import ./error | ||
|
||
declareCounter(codex_purchases_unknown, "codex purchases unknown") | ||
|
||
type PurchaseUnknown* = ref object of ErrorHandlingState | ||
type PurchaseUnknown* = ref object of PurchaseState | ||
|
||
method `$`*(state: PurchaseUnknown): string = | ||
"unknown" | ||
|
||
method run*(state: PurchaseUnknown, machine: Machine): Future[?State] {.async.} = | ||
codex_purchases_unknown.inc() | ||
let purchase = Purchase(machine) | ||
if (request =? await purchase.market.getRequest(purchase.requestId)) and | ||
(requestState =? await purchase.market.requestState(purchase.requestId)): | ||
purchase.request = some request | ||
method run*( | ||
state: PurchaseUnknown, machine: Machine | ||
): Future[?State] {.async: (raises: []).} = | ||
try: | ||
codex_purchases_unknown.inc() | ||
let purchase = Purchase(machine) | ||
if (request =? await purchase.market.getRequest(purchase.requestId)) and | ||
(requestState =? await purchase.market.requestState(purchase.requestId)): | ||
purchase.request = some request | ||
|
||
case requestState | ||
of RequestState.New: | ||
return some State(PurchaseSubmitted()) | ||
of RequestState.Started: | ||
return some State(PurchaseStarted()) | ||
of RequestState.Cancelled: | ||
return some State(PurchaseCancelled()) | ||
of RequestState.Finished: | ||
return some State(PurchaseFinished()) | ||
of RequestState.Failed: | ||
return some State(PurchaseFailed()) | ||
case requestState | ||
of RequestState.New: | ||
return some State(PurchaseSubmitted()) | ||
of RequestState.Started: | ||
return some State(PurchaseStarted()) | ||
of RequestState.Cancelled: | ||
return some State(PurchaseCancelled()) | ||
of RequestState.Finished: | ||
return some State(PurchaseFinished()) | ||
of RequestState.Failed: | ||
return some State(PurchaseFailed()) | ||
except CancelledError as e: | ||
trace "PurchaseUnknown.run was cancelled", error = e.msgDetail | ||
except CatchableError as e: | ||
error "Error during PurchaseUnknown.run", error = e.msgDetail | ||
return some State(PurchaseErrored(error: e)) |
Oops, something went wrong.