From d2882b1d85b296d06e430af0981076c028382487 Mon Sep 17 00:00:00 2001 From: Tim Zhang Date: Fri, 13 Nov 2020 17:03:16 +0800 Subject: [PATCH] Print cause when println!("{}") > Print like following: unable to write to a control group file caused by: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }) } Signed-off-by: Tim Zhang --- src/error.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index a8cd65c..26c86a8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -66,7 +66,11 @@ impl fmt::Display for Error { ErrorKind::Other => "an unknown error".to_string(), }; - write!(f, "{}", msg) + if let Some(cause) = &self.cause { + write!(f, "{} caused by: {:?}", msg, cause) + } else { + write!(f, "{}", msg) + } } }