Skip to content

Commit

Permalink
Use existing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Nov 29, 2024
1 parent d078390 commit c7dd81d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
14 changes: 4 additions & 10 deletions crates/driver/src/domain/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use {
solution::Solution,
};

use crate::domain::competition::Error::QueueAwaitingDeadlineExceeded;
use crate::domain::time::DeadlineExceeded;

/// An ongoing competition. There is one competition going on per solver at any
/// time. The competition stores settlements to solutions generated by the
Expand Down Expand Up @@ -346,12 +346,12 @@ impl Competition {

self.settle_queue.try_send(request).map_err(|err| {
tracing::error!(?err, "Failed to enqueue /settle request");
Error::UnableToEnqueue
Error::SubmissionError
})?;

response_rx.await.map_err(|err| {
tracing::error!(?err, "Failed to dequeue /settle response");
Error::UnableToDequeue
Error::SubmissionError
})?
}

Expand All @@ -367,7 +367,7 @@ impl Competition {
response_sender,
} = request;
if self.eth.current_block().borrow().number >= submission_deadline {
if let Err(err) = response_sender.send(Err(QueueAwaitingDeadlineExceeded)) {
if let Err(err) = response_sender.send(Err(DeadlineExceeded.into())) {
tracing::error!(
?err,
"settle deadline exceeded. unable to return a response"
Expand Down Expand Up @@ -579,14 +579,8 @@ pub enum Error {
SolutionNotAvailable,
#[error("{0:?}")]
DeadlineExceeded(#[from] time::DeadlineExceeded),
#[error("deadline exceeded while waiting for a queue")]
QueueAwaitingDeadlineExceeded,
#[error("solver error: {0:?}")]
Solver(#[from] solver::Error),
#[error("failed to submit the solution")]
SubmissionError,
#[error("unable to enqueue the request")]
UnableToEnqueue,
#[error("unable to dequeue the result")]
UnableToDequeue,
}
13 changes: 0 additions & 13 deletions crates/driver/src/infra/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ enum Kind {
SolverFailed,
SolutionNotAvailable,
DeadlineExceeded,
QueueAwaitingDeadlineExceeded,
Unknown,
InvalidAuctionId,
MissingSurplusFee,
InvalidTokens,
InvalidAmounts,
QuoteSameTokens,
FailedToSubmit,
UnableToEnqueueRequest,
UnableToDequeueResult,
}

#[derive(Debug, Serialize)]
Expand All @@ -42,9 +39,6 @@ impl From<Kind> for (hyper::StatusCode, axum::Json<Error>) {
/solve returned"
}
Kind::DeadlineExceeded => "Exceeded solution deadline",
Kind::QueueAwaitingDeadlineExceeded => {
"Exceeded solution deadline while waiting in the queue"
}
Kind::Unknown => "An unknown error occurred",
Kind::InvalidAuctionId => "Invalid ID specified in the auction",
Kind::MissingSurplusFee => "Auction contains a limit order with no surplus fee",
Expand All @@ -57,8 +51,6 @@ impl From<Kind> for (hyper::StatusCode, axum::Json<Error>) {
or sell amount"
}
Kind::FailedToSubmit => "Could not submit the solution to the blockchain",
Kind::UnableToEnqueueRequest => "Could not enqueue the request",
Kind::UnableToDequeueResult => "Could not dequeue the result",
};
(
hyper::StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -89,13 +81,8 @@ impl From<competition::Error> for (hyper::StatusCode, axum::Json<Error>) {
let error = match value {
competition::Error::SolutionNotAvailable => Kind::SolutionNotAvailable,
competition::Error::DeadlineExceeded(_) => Kind::DeadlineExceeded,
competition::Error::QueueAwaitingDeadlineExceeded => {
Kind::QueueAwaitingDeadlineExceeded
}
competition::Error::Solver(_) => Kind::SolverFailed,
competition::Error::SubmissionError => Kind::FailedToSubmit,
competition::Error::UnableToEnqueue => Kind::UnableToEnqueueRequest,
competition::Error::UnableToDequeue => Kind::UnableToDequeueResult,
};
error.into()
}
Expand Down
3 changes: 0 additions & 3 deletions crates/driver/src/infra/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,10 @@ fn competition_error(err: &competition::Error) -> &'static str {
match err {
competition::Error::SolutionNotAvailable => "SolutionNotAvailable",
competition::Error::DeadlineExceeded(_) => "DeadlineExceeded",
competition::Error::QueueAwaitingDeadlineExceeded => "QueueAwaitingDeadlineExceeded",
competition::Error::Solver(solver::Error::Http(_)) => "SolverHttpError",
competition::Error::Solver(solver::Error::Deserialize(_)) => "SolverDeserializeError",
competition::Error::Solver(solver::Error::Dto(_)) => "SolverDtoError",
competition::Error::SubmissionError => "SubmissionError",
competition::Error::UnableToEnqueue => "UnableToEnqueue",
competition::Error::UnableToDequeue => "UnableToDequeue",
}
}

Expand Down

0 comments on commit c7dd81d

Please sign in to comment.