blueprint_core/
error.rs

1use core::fmt;
2
3/// Alias for a type-erased error type.
4pub type BoxError = alloc::boxed::Box<dyn core::error::Error + Send + Sync>;
5pub type CloneableError = alloc::sync::Arc<dyn core::error::Error + Send + Sync>;
6
7/// Errors that can happen when using `blueprint-sdk` job routing.
8#[derive(Debug, Clone)]
9pub struct Error {
10    inner: CloneableError,
11}
12
13impl Error {
14    /// Create a new `Error` from a boxable error.
15    pub fn new(error: impl Into<BoxError>) -> Self {
16        Self {
17            inner: CloneableError::from(error.into()),
18        }
19    }
20
21    /// Convert an `Error` back into the underlying trait object.
22    pub fn into_inner(self) -> CloneableError {
23        self.inner
24    }
25}
26
27impl fmt::Display for Error {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        self.inner.fmt(f)
30    }
31}
32
33impl core::error::Error for Error {
34    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
35        Some(&*self.inner)
36    }
37}