Skip to content

Commit

Permalink
Expose error creation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest committed Oct 25, 2022
1 parent 57edfa5 commit 52b2a0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 15 additions & 4 deletions workspaces/src/error/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl Error {
}
}

pub(crate) fn full<T, E>(kind: ErrorKind, msg: T, error: E) -> Self
/// Construct a workspaces [`Error`] with the full details of an error which includes
/// the internal error it references, the custom error message with further context
/// and the [`ErrorKind`] that represents the category of error.
pub fn full<T, E>(kind: ErrorKind, msg: T, error: E) -> Self
where
T: Into<Cow<'static, str>>,
E: Into<Box<dyn std::error::Error + Send + Sync>>,
Expand All @@ -49,7 +52,10 @@ impl Error {
}
}

pub(crate) fn custom<E>(kind: ErrorKind, error: E) -> Self
/// Construct a workspaces [`Error`] with the details of an error which includes
/// the internal error it references and the [`ErrorKind`] that represents the
/// category of error.
pub fn custom<E>(kind: ErrorKind, error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Expand All @@ -61,7 +67,10 @@ impl Error {
}
}

pub(crate) fn message<T>(kind: ErrorKind, msg: T) -> Self
/// Construct a workspaces [`Error`] with the details of an error which includes
/// the custom error message with further context and the [`ErrorKind`] that
/// represents the category of error.
pub fn message<T>(kind: ErrorKind, msg: T) -> Self
where
T: Into<Cow<'static, str>>,
{
Expand All @@ -73,7 +82,9 @@ impl Error {
}
}

pub(crate) fn simple(kind: ErrorKind) -> Self {
/// Construct a workspaces [`Error`] with the details of an error which only
/// includes the [`ErrorKind`] that represents the category of error.
pub fn simple(kind: ErrorKind) -> Self {
Self {
repr: ErrorRepr::Simple(kind),
}
Expand Down
3 changes: 3 additions & 0 deletions workspaces/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub enum ErrorKind {
/// An error from converting data.
#[error("DataConversion")]
DataConversion,
/// An error that cannot be categorized into the other error kinds.
#[error("Other")]
Other,
}

#[derive(Debug, thiserror::Error)]
Expand Down

0 comments on commit 52b2a0d

Please sign in to comment.