gix_error/concrete/
chain.rs1use crate::write_location;
2use std::fmt::{Debug, Display, Formatter};
3use std::panic::Location;
4
5pub struct ChainedError {
11 pub(crate) err: Box<dyn std::error::Error + Send + Sync + 'static>,
12 pub(crate) location: &'static Location<'static>,
13 pub(crate) source: Option<Box<ChainedError>>,
14}
15
16impl Debug for ChainedError {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 Debug::fmt(&self.err, f)
19 }
20}
21
22impl Display for ChainedError {
23 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24 Display::fmt(&self.err, f)?;
25 if !f.alternate() {
26 write_location(f, self.location)?;
27 }
28 Ok(())
29 }
30}
31
32impl std::error::Error for ChainedError {
33 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34 self.source.as_ref().map(|e| e as &(dyn std::error::Error + 'static))
35 }
36}