Add snapshot error handling to ChangeProcessor

This commit is contained in:
Lucien Greathouse
2020-03-13 20:24:14 -07:00
parent 4119a510f5
commit a95ffe1d31
3 changed files with 39 additions and 7 deletions

18
src/error.rs Normal file
View File

@@ -0,0 +1,18 @@
use std::{error::Error, fmt};
/// Wrapper type to print errors with source-chasing.
pub struct ErrorDisplay<E>(pub E);
impl<E: Error> fmt::Display for ErrorDisplay<E> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
writeln!(formatter, "{}", self.0)?;
let mut current_err: &dyn Error = &self.0;
while let Some(source) = current_err.source() {
writeln!(formatter, " caused by {}", source)?;
current_err = &*source;
}
Ok(())
}
}