mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 19:18:50 +00:00
Add backtrace information to errors where relevant. (#166)
* Add backtrace information to errors where relevant. * More backtrace information. * Add to the FAQ.
This commit is contained in:
@ -170,6 +170,12 @@ pub enum Error {
|
||||
|
||||
#[error(transparent)]
|
||||
Wrapped(Box<dyn std::error::Error + Send + Sync>),
|
||||
|
||||
#[error("{inner}\n{backtrace}")]
|
||||
WithBacktrace {
|
||||
inner: Box<Self>,
|
||||
backtrace: Box<std::backtrace::Backtrace>,
|
||||
},
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
@ -178,4 +184,16 @@ impl Error {
|
||||
pub fn wrap(err: impl std::error::Error + Send + Sync + 'static) -> Self {
|
||||
Self::Wrapped(Box::new(err))
|
||||
}
|
||||
|
||||
pub fn bt(self) -> Self {
|
||||
let backtrace = std::backtrace::Backtrace::capture();
|
||||
match backtrace.status() {
|
||||
std::backtrace::BacktraceStatus::Disabled
|
||||
| std::backtrace::BacktraceStatus::Unsupported => self,
|
||||
_ => Self::WithBacktrace {
|
||||
inner: Box::new(self),
|
||||
backtrace: Box::new(backtrace),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user