Skip to content

Commit

Permalink
Use unstable backtrace feature
Browse files Browse the repository at this point in the history
This replaces the backtrace crate and removes quite a few recursive
dependencies. There was a proposal to stabilize backtrace, but it was
decided that it is better to wait until the interface with the Error
trait is decided. See
rust-lang/rust#72981
  • Loading branch information
dalcde committed Feb 27, 2021
1 parent f163fdd commit 97dfbd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions ext/crates/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@ authors = ["Dexter Chua <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
backtrace = "0.3"
8 changes: 5 additions & 3 deletions ext/crates/error/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![feature(backtrace)]
use std::error::Error as StdError;
use std::backtrace::Backtrace;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug)]
pub struct Error {
error: Box<dyn StdError + Send + Sync + 'static>,
backtrace: backtrace::Backtrace,
backtrace: Backtrace,
}

impl Error {
Expand All @@ -16,7 +18,7 @@ impl Error {
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{}", self.error)?;
writeln!(f, "{:?}", self.backtrace)?;
writeln!(f, "{}", self.backtrace)?;
Ok(())
}
}
Expand All @@ -25,7 +27,7 @@ impl<E: StdError + Send + Sync + 'static> From<E> for Error {
fn from(error: E) -> Error {
Self {
error: Box::new(error),
backtrace: backtrace::Backtrace::new(),
backtrace: Backtrace::capture(),
}
}
}
Expand Down

0 comments on commit 97dfbd7

Please sign in to comment.