From eb7502f52ee400f652c8114200aeb3d054821e2c Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Mon, 28 Jan 2019 14:57:01 +0100 Subject: [PATCH] implement display for EcloadError --- .idea/workspace.xml | 76 ++++++++++++++++++++++++++------------------- src/error.rs | 8 +++++ src/loader.rs | 8 ++--- src/main.rs | 2 +- 4 files changed, 57 insertions(+), 37 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6feebea..047ca12 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,8 @@ + + @@ -14,11 +16,11 @@ - + - - + + @@ -26,8 +28,8 @@ - - + + @@ -36,11 +38,15 @@ - + - - + + + + + + @@ -61,6 +67,8 @@ Px PageFormat format + saved + error! @@ -70,12 +78,12 @@ @@ -157,7 +165,7 @@ - + @@ -165,7 +173,7 @@ - + @@ -307,24 +315,6 @@ - - - - - - - - - - - - - - - - - - @@ -351,8 +341,30 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/error.rs b/src/error.rs index 16fe4b0..a7f5132 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +use std::fmt; + #[derive(Debug)] /// Convert different errors into a common one. pub enum EcloadError { @@ -8,6 +10,12 @@ pub enum EcloadError { ImageError(image::ImageError), } +impl fmt::Display for EcloadError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self) + } +} + impl From for EcloadError { fn from(e: std::io::Error) -> Self { EcloadError::StdError(e) diff --git a/src/loader.rs b/src/loader.rs index 2817b75..0eea154 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -148,7 +148,7 @@ impl EcLoader { let image_bmp = match EcLoader::get_img_as_bmp(&entry.path()) { Ok(image_data) => image_data, Err(err) => { - error!("could not decode {}: {:?}", entry.path().display(), err); + error!("could not decode {}: {}", entry.path().display(), err); continue; } }; @@ -179,7 +179,7 @@ impl EcLoader { } let pdf_file_path = out_dir.join(format!("{}.pdf", title)); - info!("saved to {}", pdf_file_path.display()); + info!("saving to to {}...", pdf_file_path.display()); let pdf_file = File::create(pdf_file_path)?; doc.save(&mut BufWriter::new(pdf_file))?; @@ -219,7 +219,7 @@ impl EcLoader { Ok(download_link) => download_link, Err(err) => { error!( - "could not find download link for {} with format {}: {:?}", + "could not find download link for {} with format {}: {}", &page_link, format, err ); continue; @@ -235,7 +235,7 @@ impl EcLoader { let mut page_download = match reqwest::get(&download_link) { Ok(response) => response, Err(err) => { - error!("could not download {}: {:?}", download_link, err); + error!("could not download {}: {}", download_link, err); continue; } }; diff --git a/src/main.rs b/src/main.rs index 0e9192f..9a0fbe2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ fn main() { match run(&out_path, size, id, title) { Ok(_) => info!("finished!"), - Err(e) => error!("something went wrong: {:?}", e), + Err(e) => error!("something went wrong: {}", e), }; }