implement display for EcloadError

This commit is contained in:
Sebastian Hugentobler 2019-01-28 14:57:01 +01:00
parent 782fff9ac8
commit eb7502f52e
4 changed files with 57 additions and 37 deletions

View File

@ -2,6 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a321fd91-c97c-4f17-b620-fd9934708617" name="Default Changelist" comment=""> <list default="true" id="a321fd91-c97c-4f17-b620-fd9934708617" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/src/error.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/error.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/loader.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/loader.rs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main.rs" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.rs" afterDir="false" />
</list> </list>
<ignored path="$PROJECT_DIR$/out/" /> <ignored path="$PROJECT_DIR$/out/" />
@ -14,11 +16,11 @@
</component> </component>
<component name="FileEditorManager"> <component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300"> <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.rs"> <entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="406"> <state relative-caret-position="355">
<caret line="53" column="67" selection-start-line="53" selection-start-column="67" selection-end-line="53" selection-end-column="67" /> <caret line="64" column="23" lean-forward="true" selection-start-line="64" selection-start-column="23" selection-end-line="64" selection-end-column="23" />
</state> </state>
</provider> </provider>
</entry> </entry>
@ -26,8 +28,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/loader.rs"> <entry file="file://$PROJECT_DIR$/src/loader.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225"> <state relative-caret-position="249">
<caret line="15" column="47" selection-start-line="15" selection-start-column="47" selection-end-line="15" selection-end-column="47" /> <caret line="222" column="47" selection-start-line="222" selection-start-column="47" selection-end-line="222" selection-end-column="47" />
<folding> <folding>
<element signature="e#4669#4670#0" expanded="true" /> <element signature="e#4669#4670#0" expanded="true" />
<element signature="e#4723#4724#0" expanded="true" /> <element signature="e#4723#4724#0" expanded="true" />
@ -36,11 +38,15 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/error.rs"> <entry file="file://$PROJECT_DIR$/src/error.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15"> <state relative-caret-position="240">
<caret line="1" column="47" selection-start-line="1" selection-start-column="47" selection-end-line="1" selection-end-column="47" /> <caret line="16" column="1" selection-start-line="16" selection-start-column="1" selection-end-line="16" selection-end-column="1" />
<folding>
<element signature="e#353#354#0" expanded="true" />
<element signature="e#383#384#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
@ -61,6 +67,8 @@
<find>Px</find> <find>Px</find>
<find>PageFormat</find> <find>PageFormat</find>
<find>format</find> <find>format</find>
<find>saved</find>
<find>error!</find>
</findStrings> </findStrings>
</component> </component>
<component name="Git.Settings"> <component name="Git.Settings">
@ -70,12 +78,12 @@
<option name="CHANGED_PATHS"> <option name="CHANGED_PATHS">
<list> <list>
<option value="$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.2.10/src/types/pdf_document.rs" /> <option value="$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/printpdf-0.2.10/src/types/pdf_document.rs" />
<option value="$PROJECT_DIR$/src/loader.rs" />
<option value="$PROJECT_DIR$/src/error.rs" />
<option value="$PROJECT_DIR$/Cargo.toml" /> <option value="$PROJECT_DIR$/Cargo.toml" />
<option value="$PROJECT_DIR$/LICENSE" /> <option value="$PROJECT_DIR$/LICENSE" />
<option value="$PROJECT_DIR$/README.md" /> <option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/src/main.rs" /> <option value="$PROJECT_DIR$/src/main.rs" />
<option value="$PROJECT_DIR$/src/loader.rs" />
<option value="$PROJECT_DIR$/src/error.rs" />
</list> </list>
</option> </option>
</component> </component>
@ -157,7 +165,7 @@
<window_info id="Favorites" order="3" side_tool="true" /> <window_info id="Favorites" order="3" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" /> <window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.37962264" /> <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.37962264" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" /> <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -165,7 +173,7 @@
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" /> <window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" /> <window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" /> <window_info anchor="bottom" id="Database Changes" order="9" />
<window_info active="true" anchor="bottom" id="Terminal" order="10" visible="true" weight="0.32981133" /> <window_info anchor="bottom" id="Terminal" order="10" weight="0.32981133" />
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" /> <window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" /> <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@ -307,24 +315,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/error.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="15">
<caret line="1" column="47" selection-start-line="1" selection-start-column="47" selection-end-line="1" selection-end-column="47" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/loader.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="225">
<caret line="15" column="47" selection-start-line="15" selection-start-column="47" selection-end-line="15" selection-end-column="47" />
<folding>
<element signature="e#4669#4670#0" expanded="true" />
<element signature="e#4723#4724#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/LICENSE"> <entry file="file://$PROJECT_DIR$/LICENSE">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="707"> <state relative-caret-position="707">
@ -351,8 +341,30 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/src/main.rs"> <entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="406"> <state relative-caret-position="355">
<caret line="53" column="67" selection-start-line="53" selection-start-column="67" selection-end-line="53" selection-end-column="67" /> <caret line="64" column="23" lean-forward="true" selection-start-line="64" selection-start-column="23" selection-end-line="64" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/loader.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="249">
<caret line="222" column="47" selection-start-line="222" selection-start-column="47" selection-end-line="222" selection-end-column="47" />
<folding>
<element signature="e#4669#4670#0" expanded="true" />
<element signature="e#4723#4724#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/error.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="240">
<caret line="16" column="1" selection-start-line="16" selection-start-column="1" selection-end-line="16" selection-end-column="1" />
<folding>
<element signature="e#353#354#0" expanded="true" />
<element signature="e#383#384#0" expanded="true" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>

View File

@ -1,3 +1,5 @@
use std::fmt;
#[derive(Debug)] #[derive(Debug)]
/// Convert different errors into a common one. /// Convert different errors into a common one.
pub enum EcloadError { pub enum EcloadError {
@ -8,6 +10,12 @@ pub enum EcloadError {
ImageError(image::ImageError), ImageError(image::ImageError),
} }
impl fmt::Display for EcloadError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}
impl From<std::io::Error> for EcloadError { impl From<std::io::Error> for EcloadError {
fn from(e: std::io::Error) -> Self { fn from(e: std::io::Error) -> Self {
EcloadError::StdError(e) EcloadError::StdError(e)

View File

@ -148,7 +148,7 @@ impl EcLoader {
let image_bmp = match EcLoader::get_img_as_bmp(&entry.path()) { let image_bmp = match EcLoader::get_img_as_bmp(&entry.path()) {
Ok(image_data) => image_data, Ok(image_data) => image_data,
Err(err) => { Err(err) => {
error!("could not decode {}: {:?}", entry.path().display(), err); error!("could not decode {}: {}", entry.path().display(), err);
continue; continue;
} }
}; };
@ -179,7 +179,7 @@ impl EcLoader {
} }
let pdf_file_path = out_dir.join(format!("{}.pdf", title)); 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)?; let pdf_file = File::create(pdf_file_path)?;
doc.save(&mut BufWriter::new(pdf_file))?; doc.save(&mut BufWriter::new(pdf_file))?;
@ -219,7 +219,7 @@ impl EcLoader {
Ok(download_link) => download_link, Ok(download_link) => download_link,
Err(err) => { Err(err) => {
error!( error!(
"could not find download link for {} with format {}: {:?}", "could not find download link for {} with format {}: {}",
&page_link, format, err &page_link, format, err
); );
continue; continue;
@ -235,7 +235,7 @@ impl EcLoader {
let mut page_download = match reqwest::get(&download_link) { let mut page_download = match reqwest::get(&download_link) {
Ok(response) => response, Ok(response) => response,
Err(err) => { Err(err) => {
error!("could not download {}: {:?}", download_link, err); error!("could not download {}: {}", download_link, err);
continue; continue;
} }
}; };

View File

@ -77,7 +77,7 @@ fn main() {
match run(&out_path, size, id, title) { match run(&out_path, size, id, title) {
Ok(_) => info!("finished!"), Ok(_) => info!("finished!"),
Err(e) => error!("something went wrong: {:?}", e), Err(e) => error!("something went wrong: {}", e),
}; };
} }