Skip to content

Commit

Permalink
Replace failure with thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
bbhtt authored and barthalion committed Jan 4, 2025
1 parent 6ebfec3 commit a822622
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 84 deletions.
123 changes: 62 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tempfile = "3.0"
thiserror = "1.0.43"
time = "0.1"
tokio = { version = "1.18", features = ["time", "macros", "rt", "rt-multi-thread"] }
tokio-compat = { version = "0.1", features = ["rt-full"] }
Expand Down
28 changes: 14 additions & 14 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use actix_web::error::BlockingError;
use actix_web::http::StatusCode;
use actix_web::{error::ResponseError, HttpResponse};
use diesel::result::Error as DieselError;
use failure::Fail;
use serde_json::json;
use std::io;
use thiserror::Error;

#[derive(Fail, Debug, Clone)]
#[derive(Error, Debug, Clone)]
pub enum DeltaGenerationError {
#[fail(display = "{}", _0)]
#[error("{0}")]
Failed(String),
}

Expand All @@ -31,12 +31,12 @@ impl From<OstreeError> for DeltaGenerationError {
}
}

#[derive(Fail, Debug, Clone)]
#[derive(Error, Debug, Clone)]
pub enum JobError {
#[fail(display = "InternalError: {}", _0)]
#[error("InternalError: {0}")]
InternalError(String),

#[fail(display = "DbError: {}", _0)]
#[error("DbError: {0}")]
DBError(String),
}

Expand Down Expand Up @@ -95,27 +95,27 @@ impl From<io::Error> for JobError {
}
}

#[derive(Fail, Debug)]
#[derive(Error, Debug)]
pub enum ApiError {
#[fail(display = "Internal Server Error ({})", _0)]
#[error("Internal Server Error ({0})")]
InternalServerError(String),

#[fail(display = "NotFound")]
#[error("NotFound")]
NotFound,

#[fail(display = "BadRequest: {}", _0)]
#[error("BadRequest: {0}")]
BadRequest(String),

#[fail(display = "WrongRepoState({}): {}", _2, _0)]
#[error("WrongRepoState({2}): {0}")]
WrongRepoState(String, String, String),

#[fail(display = "WrongPublishedState({}): {}", _2, _0)]
#[error("WrongPublishedState({2}): {0}")]
WrongPublishedState(String, String, String),

#[fail(display = "InvalidToken: {}", _0)]
#[error("InvalidToken: {0}")]
InvalidToken(String),

#[fail(display = "NotEnoughPermissions")]
#[error("NotEnoughPermissions")]
NotEnoughPermissions(String),
}

Expand Down
Loading

0 comments on commit a822622

Please sign in to comment.