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 <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-11-13 17:03:16 +08:00
parent abcb5ed031
commit d2882b1d85

View File

@@ -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)
}
}
}