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">
<component name="ChangeListManager">
<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" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
@ -14,11 +16,11 @@
</component>
<component name="FileEditorManager">
<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">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="406">
<caret line="53" column="67" selection-start-line="53" selection-start-column="67" selection-end-line="53" selection-end-column="67" />
<state relative-caret-position="355">
<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>
@ -26,8 +28,8 @@
<file pinned="false" current-in-tab="false">
<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" />
<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" />
@ -36,11 +38,15 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<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 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>
</provider>
</entry>
@ -61,6 +67,8 @@
<find>Px</find>
<find>PageFormat</find>
<find>format</find>
<find>saved</find>
<find>error!</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -70,12 +78,12 @@
<option name="CHANGED_PATHS">
<list>
<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$/LICENSE" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/src/main.rs" />
<option value="$PROJECT_DIR$/src/loader.rs" />
<option value="$PROJECT_DIR$/src/error.rs" />
</list>
</option>
</component>
@ -157,7 +165,7 @@
<window_info id="Favorites" order="3" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<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="Cvs" order="4" weight="0.25" />
<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="Version Control" order="8" />
<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="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" />
@ -307,24 +315,6 @@
</state>
</provider>
</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">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="707">
@ -351,8 +341,30 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="406">
<caret line="53" column="67" selection-start-line="53" selection-start-column="67" selection-end-line="53" selection-end-column="67" />
<state relative-caret-position="355">
<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>
</provider>
</entry>

View File

@ -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<std::io::Error> for EcloadError {
fn from(e: std::io::Error) -> Self {
EcloadError::StdError(e)

View File

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

View File

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