summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-05-06 19:28:34 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-05-06 19:28:34 +0000
commit27b617cbaa9e6d4fb58a0b971b428a05da8ec5d9 (patch)
tree08067bf4290982e4a717ba55a660714084370158 /src/error.rs
parentc2cbccd45a2c356e458abc8bbef3193434e8572a (diff)
parent52ccfa5a1bf2893bdc63ff1bad2b2a88ca86ef95 (diff)
downloadsubplot-27b617cbaa9e6d4fb58a0b971b428a05da8ec5d9.tar.gz
Merge branch 'liw/tidy-up-error' into 'main'
tidy up error handling a bit See merge request subplot/subplot!275
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs83
1 files changed, 34 insertions, 49 deletions
diff --git a/src/error.rs b/src/error.rs
index c93141e..a42298d 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -259,60 +259,48 @@ 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),
- /// Pandoc error
- ///
- /// Subplot got an error from Panoc. This is a generic wrapper for
- /// any kinds of Pandoc errors.
- #[error(transparent)]
- PandocError {
- /// The wrapped error.
- #[from]
- source: pandoc::PandocError,
- },
+ /// 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),
+
+ /// Error executing Pandoc.
+ #[error("Pandoc failed")]
+ Pandoc(#[source] pandoc::PandocError),
/// Regular expression error
///
/// Subplot uses regular expressions. This is a generic wrapper for
/// any kinds of errors related to that.
- #[error(transparent)]
- RegexError {
- /// The wrapped error.
- #[from]
- source: regex::Error,
- },
+ #[error("Failed to compile regular expression: {0:?}")]
+ Regex(String, #[source] regex::Error),
- /// JSON error
- ///
- /// Subplot parses and generates JSON. This is a generic wrapper
- /// for any kinds of errors related to that.
- #[error(transparent)]
- JsonError {
- /// The wrapped error.
- #[from]
- source: serde_json::Error,
- },
+ /// Error parsing the Pandoc abstract syntax tree as JSON.
+ #[error("Failed to parse document AST as JSON")]
+ AstJson(#[source] serde_json::Error),
- /// YAML error
- ///
- /// Subplot parses YAML. This is a generic wrapper for any kinds
- /// of errors related to that.
- #[error(transparent)]
- YamlError {
- /// The wrapped error.
- #[from]
- source: serde_yaml::Error,
- },
+ /// Error parsing YAML metadata for document.
+ #[error("Failed to parse YAML metadata")]
+ Metadata(#[source] serde_yaml::Error),
/// Abstract syntax tree error.
#[error(transparent)]
@@ -336,9 +324,6 @@ impl SubplotError {
}
}
-/// A result type for this crate.
-pub type Result<T> = std::result::Result<T, SubplotError>;
-
/// A warning, or non-fatal error.
///
/// Errors prevent Subplot from producing output. Warnings don't do that.