This repository was archived by the owner on Aug 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ macro_rules! error_chain_processed {
86
86
pub fn iter( & self ) -> $crate:: ErrorChainIter {
87
87
$crate:: ErrorChainIter ( Some ( self ) )
88
88
}
89
+
90
+ /// Returns the backtrace associated with this error.
91
+ pub fn backtrace( & self ) -> Option <& $crate:: Backtrace > {
92
+ self . state. backtrace( )
93
+ }
89
94
}
90
95
91
96
impl :: std:: error:: Error for $error_name {
@@ -308,13 +313,6 @@ macro_rules! impl_error {
308
313
( $error_name: ident
309
314
$error_kind_name: ident
310
315
$( [ $link_error_path: path, $( #[ $meta_links: meta] ) * ] ) * ) => {
311
- impl $error_name {
312
- /// Returns the backtrace associated with this error.
313
- pub fn backtrace( & self ) -> Option <& $crate:: Backtrace > {
314
- self . state. backtrace. as_ref( ) . map( |v| & * * v)
315
- }
316
- }
317
-
318
316
impl $crate:: ChainedError for $error_name {
319
317
type ErrorKind = $error_kind_name;
320
318
Original file line number Diff line number Diff line change @@ -261,6 +261,9 @@ use std::sync::Arc;
261
261
262
262
#[ cfg( feature = "backtrace" ) ]
263
263
pub use backtrace:: Backtrace ;
264
+ #[ cfg( not( feature = "backtrace" ) ) ]
265
+ /// Dummy type used when the `backtrace` feature is disabled.
266
+ pub type Backtrace = ( ) ;
264
267
265
268
#[ macro_use]
266
269
mod quick_error;
@@ -371,6 +374,17 @@ impl Default for State {
371
374
}
372
375
}
373
376
377
+ impl State {
378
+ /// Returns the inner backtrace if present.
379
+ pub fn backtrace ( & self ) -> Option < & Backtrace > {
380
+ #[ cfg( feature = "backtrace" ) ]
381
+ let b = self . backtrace . as_ref ( ) . map ( |v| & * * v) ;
382
+ #[ cfg( not( feature = "backtrace" ) ) ]
383
+ let b = None ;
384
+ b
385
+ }
386
+ }
387
+
374
388
/// This modules show an example of code generated by the macro. IT MUST NOT BE
375
389
/// USED OUTSIDE THIS CRATE.
376
390
///
You can’t perform that action at this time.
0 commit comments