Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions tracing-error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[package]
name = "tracing-error"
# When releasing to crates.io:
# - Remove path dependencies
# - Update doc url in README.md.
# - Update CHANGELOG.md.
# - Create "v0.2.x" git tag
version = "0.2.1"
# The '0.775' series is compatible with tracing-core 0.1, but is only published privately and used by Rigetti.
version = "0.775.0"
authors = [
"Eliza Weisman <eliza@buoyant.io>",
"Jane Lusby <jlusby@yaah.dev>",
Expand Down
68 changes: 68 additions & 0 deletions tracing-error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,61 @@ where
{
self.map(Into::into)
}

/// Return a reference to the original error stored within this [`TracedError`].
///
/// ```rust
/// use tracing_error::TracedError;
/// # #[derive(Clone, Debug, PartialEq)]
/// # struct MyError(u64);
/// # impl std::fmt::Display for MyError {
/// # fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// # write!(f, "Inner Error")
/// # }
/// # }
/// # impl std::error::Error for MyError {}
///
/// let original_err = MyError(42);
///
/// let traced_err: TracedError<MyError> = TracedError::from(original_err.clone());
/// assert_eq!(traced_err.get_inner_error(), &original_err)
/// ```
pub fn get_inner_error(&self) -> &E {
&self.inner.error
}

/// Consume the [`TracedError`] and return the original error stored within.
///
/// ```rust
/// use tracing_error::TracedError;
/// # #[derive(Clone, Debug, PartialEq)]
/// # struct MyError(u64);
/// # impl std::fmt::Display for MyError {
/// # fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// # write!(f, "Inner Error")
/// # }
/// # }
/// # impl std::error::Error for MyError {}
///
/// let original_err = MyError(42);
///
/// let traced_err: TracedError<MyError> = TracedError::from(original_err.clone());
/// assert_eq!(traced_err.to_inner_error(), original_err)
/// ```
pub fn to_inner_error(self) -> E {
self.inner.error
}
}

impl<E> std::clone::Clone for TracedError<E>
where
E: Clone,
{
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}

impl<E> From<E> for TracedError<E>
Expand Down Expand Up @@ -213,6 +268,19 @@ impl ErrorImpl<Erased> {
}
}

impl<E> Clone for ErrorImpl<E>
where
E: Clone,
{
fn clone(&self) -> Self {
Self {
vtable: self.vtable,
span_trace: self.span_trace.clone(),
error: self.error.clone(),
}
}
}

struct ErrorVTable {
object_ref: unsafe fn(&ErrorImpl<Erased>) -> &(dyn Error + Send + Sync + 'static),
}
Expand Down
Loading