summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-05-06 08:39:14 +0300
committerLars Wirzenius <liw@liw.fi>2022-05-06 09:34:28 +0300
commit2b7160ebdf950ef872f785336fcfe17e0c4cb347 (patch)
tree216fb5b9c2cf5fa6121e1b2d357508a0c675e3e9 /src/error.rs
parent6498b2eecb21ad87069be8f501f35374745106d9 (diff)
downloadsubplot-2b7160ebdf950ef872f785336fcfe17e0c4cb347.tar.gz
refactor! split SubplotError::IoError into more specific errors
Replace SubplotError::IoError with ::Spawn, ::WriteToChild, ::WaitForChild, ::ReadFile, ::CreateFile, ::Writefile. IoError was a catchall error and as such, so generic that it didn't help the user to figure out what actually is wrong. For example, there was no indication what operation was attempted or on what file. The new error variants are specific. Sponsored-by: author
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/error.rs b/src/error.rs
index f9608a8..f0d76e3 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -259,16 +259,29 @@ pub enum SubplotError {
#[error("no scenarios were found matching the `{0}` template")]
NoScenariosMatched(String),
- /// I/O error
- ///
- /// Subplot did some I/O, and it failed. This is a generic wrapper
- /// for any kind of I/O error.
- #[error(transparent)]
- IoError {
- /// The wrapped error.
- #[from]
- source: std::io::Error,
- },
+ /// Failed to invoke a program.
+ #[error("Failed to invoke {0}")]
+ Spawn(PathBuf, #[source] std::io::Error),
+
+ /// Failed to write to stdin of child process.
+ #[error("Failed to write to stdin of child process")]
+ WriteToChild(#[source] std::io::Error),
+
+ /// Error when waiting for child process to finish.
+ #[error("Error when waiting for child process to finish")]
+ WaitForChild(#[source] std::io::Error),
+
+ /// Error when reading a file.
+ #[error("Error when reading {0}")]
+ ReadFile(PathBuf, #[source] std::io::Error),
+
+ /// Error when creating a file.
+ #[error("Error when creating {0}")]
+ CreateFile(PathBuf, #[source] std::io::Error),
+
+ /// Error when writing to a file.
+ #[error("Error when writing to {0}")]
+ WriteFile(PathBuf, #[source] std::io::Error),
/// Pandoc error
///