Skip to content

Commit

Permalink
chore: clean up errors and unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
dav1do committed Jun 13, 2024
1 parent f54d61c commit 7057175
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 73 deletions.
29 changes: 8 additions & 21 deletions service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,21 @@ impl Error {
impl From<Error> for recon::Error {
fn from(value: Error) -> Self {
match value {
Error::Application { error } => recon::Error::Application {
error: error.context("recon error"),
},
Error::Fatal { error } => recon::Error::Fatal {
error: error.context("recon error"),
},
Error::Transient { error } => recon::Error::Transient {
error: error.context("recon error"),
},
Error::InvalidArgument { error } => recon::Error::Application {
error: error.context("recon error"),
},
Error::Application { error } => recon::Error::Application { error },
Error::Fatal { error } => recon::Error::Fatal { error },
Error::Transient { error } => recon::Error::Transient { error },
Error::InvalidArgument { error } => recon::Error::Application { error },
}
}
}

impl From<ceramic_store::Error> for Error {
fn from(value: ceramic_store::Error) -> Self {
match value {
ceramic_store::Error::Application { error } => Error::Application {
error: error.context("store error"),
},
ceramic_store::Error::Fatal { error } => Error::Fatal {
error: error.context("store error"),
},
ceramic_store::Error::Transient { error } => Error::Transient {
error: error.context("store error"),
},
ceramic_store::Error::Application { error } => Error::Application { error },
ceramic_store::Error::Fatal { error } => Error::Fatal { error },
ceramic_store::Error::Transient { error } => Error::Transient { error },
ceramic_store::Error::InvalidArgument { error } => Error::InvalidArgument { error },
}
}
}
17 changes: 17 additions & 0 deletions store/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub enum Error {
/// The error details that may include context and other information
error: anyhow::Error,
},
#[error("InvalidArgument: {error}")]
/// Invalid client input
InvalidArgument {
/// The error details that may include context and other information
error: anyhow::Error,
},
#[error("Fatal error encountered: {error}")]
/// A fatal error that is unlikely to be recoverable, and may require terminating the process completely
Fatal {
Expand Down Expand Up @@ -45,6 +51,13 @@ impl Error {
}
}

/// Crate an InvalidArgument error
pub fn new_invalid_arg(error: impl Into<anyhow::Error>) -> Self {
Self::InvalidArgument {
error: error.into(),
}
}

/// Add context to the internal error. Works identically to `anyhow::context`
pub fn context<C>(self, context: C) -> Self
where
Expand All @@ -60,6 +73,9 @@ impl Error {
Error::Transient { error } => Self::Transient {
error: error.context(context),
},
Error::InvalidArgument { error } => Self::InvalidArgument {
error: error.context(context),
},
}
}
}
Expand Down Expand Up @@ -115,6 +131,7 @@ impl From<Error> for recon::Error {
Error::Application { error } => recon::Error::Application { error },
Error::Fatal { error } => recon::Error::Fatal { error },
Error::Transient { error } => recon::Error::Transient { error },
Error::InvalidArgument { error } => recon::Error::Application { error },
}
}
}
52 changes: 0 additions & 52 deletions store/src/sql/entities/cid.rs

This file was deleted.

0 comments on commit 7057175

Please sign in to comment.