summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index bcee4ff..c93141e 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -8,6 +8,10 @@ use thiserror::Error;
/// Define all the kinds of errors any part of this crate can return.
#[derive(Debug, Error)]
pub enum SubplotError {
+ /// Document has non-fatal errors.
+ #[error("Document has {0} warnings.")]
+ Warnings(usize),
+
/// Subplot could not find a file named as a bindings file.
#[error("binding file could not be found: {0}: {1}")]
BindingsFileNotFound(PathBuf, std::io::Error),
@@ -334,3 +338,65 @@ 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.
+#[derive(Debug, Clone, thiserror::Error)]
+pub enum Warning {
+ /// Document refers to an embedded file that doesn't exist.
+ #[error(
+ "Document refers to an embedded file that doesn't exist: \"{1}\"\n in scenario \"{0}\""
+ )]
+ UnknownEmbeddedFile(String, String),
+
+ /// Embedded file is not used by any scenario.
+ #[error("Embedded file is not used by any scenario: \"{0}\"")]
+ UnusedEmbeddedFile(String),
+
+ /// Missing step implementation.
+ #[error("Missing step implementation: \"{1}\"\n in scenario \"{0}\"")]
+ MissingStepImplementation(String, String),
+
+ /// Unknown binding when typesetting a scenario.
+ #[error("Unknown binding: {0}")]
+ UnknownBinding(String),
+
+ /// Pikchr failed during typesetting.
+ #[error("Markup using pikchr failed: {0}")]
+ Pikchr(String),
+
+ /// Dot failed during typesetting.
+ #[error("Markup using dot failed: {0}")]
+ Dot(String),
+
+ /// Plantuml failed during typesetting.
+ #[error("Markup using plantuml failed: {0}")]
+ Plantuml(String),
+}
+
+/// A list of warnings.
+///
+/// Subplot collects warnings into this structure so that they can be
+/// processed at the end.
+#[derive(Debug, Default)]
+pub struct Warnings {
+ warnings: Vec<Warning>,
+}
+
+impl Warnings {
+ /// Append a warning to the list.
+ pub fn push(&mut self, w: Warning) {
+ self.warnings.push(w);
+ }
+
+ /// Append all warnings from one list to another.
+ pub fn push_all(&mut self, mut other: Warnings) {
+ self.warnings.append(&mut other.warnings);
+ }
+
+ /// Return a slice with all the warnings in the list.
+ pub fn warnings(&self) -> &[Warning] {
+ &self.warnings
+ }
+}