summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/errors.rs6
-rw-r--r--src/preview/preview_transformer.rs25
2 files changed, 22 insertions, 9 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 789b091..b66630a 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -127,3 +127,9 @@ custom_error! {pub SvgError
Internal { message: &'static str } = "Internal error : {message}",
Svg {source: resvg::usvg::Error} = "SVG Error: {source}",
}
+
+custom_error! {pub PreviewTransformerError
+ Io {source: io::Error} = "IO Error : {source}",
+ ProcessInterrupted = "Process interrupted",
+ ProcessFailed { code: i32 } = "Execution failed with code {code}",
+}
diff --git a/src/preview/preview_transformer.rs b/src/preview/preview_transformer.rs
index 1a828cc..72f144a 100644
--- a/src/preview/preview_transformer.rs
+++ b/src/preview/preview_transformer.rs
@@ -118,7 +118,7 @@ impl PreviewTransformer {
&self,
input_path: &Path,
temp_dir: &Path,
- ) -> Result<PathBuf, ProgramError> {
+ ) -> Result<PathBuf, PreviewTransformerError> {
let hash = {
let mut hasher = DefaultHasher::new();
input_path.hash(&mut hasher);
@@ -149,14 +149,21 @@ impl PreviewTransformer {
} else {
process.stdout(std::fs::File::create(&output_path)?);
}
- let res = process
+ let exit_status = process
.spawn()
- .and_then(|mut p| p.wait())
- .map_err(|source| ProgramError::LaunchError {
- program: self.command[0].clone(),
- source,
- });
- info!("conversion result: {:?}", res);
- Ok(output_path)
+ .and_then(|mut p| p.wait())?;
+ if exit_status.success() {
+ Ok(output_path)
+ } else {
+ // we remove the output file if the process failed, so that
+ // it's not returned on the next call
+ let _ = std::fs::remove_file(&output_path);
+ match exit_status.code() {
+ Some(code) => Err(PreviewTransformerError::ProcessFailed {
+ code,
+ }),
+ None => Err(PreviewTransformerError::ProcessInterrupted),
+ }
+ }
}
}