summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid-core/src/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs
index 1147e40fd6..8de9002c1a 100644
--- a/talpid-core/src/lib.rs
+++ b/talpid-core/src/lib.rs
@@ -62,7 +62,11 @@ mod linux;
trait ErrorExt {
+ /// Creates a string representation of the entire error chain.
fn display_chain(&self) -> String;
+
+ /// Like [`display_chain`] but with an extra message at the start of the chain
+ fn display_chain_with_msg(&self, msg: &str) -> String;
}
impl<E: std::error::Error> ErrorExt for E {
@@ -75,4 +79,14 @@ impl<E: std::error::Error> ErrorExt for E {
}
s
}
+
+ fn display_chain_with_msg(&self, msg: &str) -> String {
+ let mut s = format!("Error: {}\nCaused by: {}", msg, self);
+ let mut source = self.source();
+ while let Some(error) = source {
+ s.push_str(&format!("\nCaused by: {}", error));
+ source = error.source();
+ }
+ s
+ }
}