diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 116 |
1 files changed, 85 insertions, 31 deletions
diff --git a/src/error.rs b/src/error.rs index a42298d..b89e94b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,6 @@ +use crate::html::{HtmlError, Location}; use crate::matches::MatchedSteps; +use crate::md::MdError; use std::path::PathBuf; use std::process::Output; @@ -8,17 +10,25 @@ use thiserror::Error; /// Define all the kinds of errors any part of this crate can return. #[derive(Debug, Error)] pub enum SubplotError { + /// Scenario step does not start at the beginning of the line. + #[error("Scenario step is indented: {0}")] + NotAtBoln(String), + /// Document has non-fatal errors. #[error("Document has {0} warnings.")] Warnings(usize), + /// Subplot could not find its CSS file. + #[error("failed to find CSS file: {0}")] + CssFileNotFound(PathBuf, #[source] std::io::Error), + /// 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), + #[error("binding file could not be found: {0}")] + BindingsFileNotFound(PathBuf, #[source] std::io::Error), /// Subplot could not find a file named as a functions file. - #[error("functions file could not be found: {0}: {1}")] - FunctionsFileNotFound(PathBuf, std::io::Error), + #[error("functions file could not be found: {0}")] + FunctionsFileNotFound(PathBuf, #[source] std::io::Error), /// The simple pattern specifies a kind that is unknown. #[error("simple pattern kind {0} is unknown")] @@ -44,6 +54,13 @@ pub enum SubplotError { #[error("binding file failed to parse: {0}")] BindingFileParseError(PathBuf, #[source] Box<SubplotError>), + /// Binding lacks documentation. + /// + /// Add a `doc` field to the binding with text the documents the + /// binding. + #[error("binding lacks documentation: {0}: {1} {2}")] + NoBindingDoc(PathBuf, crate::StepKind, String), + /// Scenario step does not match a known binding /// /// This may be due to the binding missing entirely, or that the @@ -138,18 +155,6 @@ pub enum SubplotError { #[error("document lacks specified template support")] TemplateSupportNotPresent, - /// Pandoc AST is not JSON - /// - /// Subplot acts as a Pandoc filter, and as part of that Pandoc - /// constructs an _abstract syntax tree_ from the input document, - /// and feeds it to the filter as JSON. However, when Subplot was - /// parsing the AST, it wasn't JSON. - /// - /// This probably means there's something wrong with Pandoc, it's - /// Rust bindings, or Subplot. - #[error("Pandoc produce AST not in JSON")] - NotJson, - /// First scenario is before first heading /// /// Subplot scenarios are group by the input document's structure. @@ -158,8 +163,8 @@ pub enum SubplotError { /// scenario block before the first heading in the document. /// /// To fix, add a heading or move the scenario after a heading. - #[error("first scenario is before first heading")] - ScenarioBeforeHeading, + #[error("{0}: first scenario is before first heading")] + ScenarioBeforeHeading(Location), /// Step does not have a keyword. #[error("step has no keyword: {0}")] @@ -183,6 +188,13 @@ pub enum SubplotError { #[error("continuation keyword used too early")] ContinuationTooEarly, + /// Scenario has the same title as another scenario + /// + /// Titles of scenarios must be unique in the input document, + /// but Subplot found at least one with the same title as another. + #[error("Scenario title is duplicate: {0:?}")] + DuplicateScenario(String), + /// Embedded file has the same name as another embedded file /// /// Names of embedded files must be unique in the input document, @@ -201,7 +213,7 @@ pub enum SubplotError { /// /// The `add-newline` attribute can only take the values `auto`, `yes`, /// and `no`. - #[error("Embedded file {0} has unrecognised `add-newline={}` - valid values are auto/yes/no")] + #[error("Embedded file {0} has unrecognised `add-newline={1}` - valid values are auto/yes/no")] UnrecognisedAddNewline(String, String), /// Couldn't determine base directory from input file name. @@ -233,8 +245,8 @@ pub enum SubplotError { NoTemplateSpecDirectory(PathBuf), /// A code template has an error. - #[error("Couldn't load template {0}: {1}")] - TemplateError(String, tera::Error), + #[error("Couldn't load template {0}")] + TemplateError(String, #[source] tera::Error), /// Unknown classes in use in document #[error("Unknown classes found in the document: {0}")] @@ -283,9 +295,9 @@ pub enum SubplotError { #[error("Error when writing to {0}")] WriteFile(PathBuf, #[source] std::io::Error), - /// Error executing Pandoc. - #[error("Pandoc failed")] - Pandoc(#[source] pandoc::PandocError), + /// Error parsing markdown into HTML. + #[error(transparent)] + ParseMarkdown(#[from] HtmlError), /// Regular expression error /// @@ -294,21 +306,41 @@ pub enum SubplotError { #[error("Failed to compile regular expression: {0:?}")] Regex(String, #[source] regex::Error), - /// Error parsing the Pandoc abstract syntax tree as JSON. - #[error("Failed to parse document AST as JSON")] - AstJson(#[source] serde_json::Error), - /// Error parsing YAML metadata for document. #[error("Failed to parse YAML metadata")] Metadata(#[source] serde_yaml::Error), - /// Abstract syntax tree error. - #[error(transparent)] - Ast(#[from] crate::ast::Error), + /// Error parsing YAML metadata for document, from external file. + #[error("Failed to parse YAML metadata in {0}")] + MetadataFile(PathBuf, #[source] serde_yaml::Error), + + /// UTF8 conversion error. + #[error("failed to parse UTF8 in file {0}")] + FileUtf8(PathBuf, #[source] std::string::FromUtf8Error), /// UTF8 conversion error. #[error(transparent)] Utf8Error(#[from] std::str::Utf8Error), + + /// Markdown errors. + #[error(transparent)] + MdError(#[from] MdError), + + /// String formatting failed. + #[error("Failed in string formattiing: {0}")] + StringFormat(std::fmt::Error), + + /// Input file could not be read. + #[error("Failed to read input file {0}")] + InputFileUnreadable(PathBuf, #[source] std::io::Error), + + /// Input file mtime lookup. + #[error("Failed to get modification time of {0}")] + InputFileMtime(PathBuf, #[source] std::io::Error), + + /// Error typesetting a roadmap diagram. + #[error(transparent)] + Roadmap(#[from] roadmap::RoadmapError), } impl SubplotError { @@ -358,6 +390,18 @@ pub enum Warning { /// Plantuml failed during typesetting. #[error("Markup using plantuml failed: {0}")] Plantuml(String), + + /// A code block has an identifier but is not marked as a file or example + #[error("Code block has identifier but lacks file or example class. Is this a mistake? #{0} at {1}")] + MissingAppropriateClassOnNamedCodeBlock(String, String), + + /// A capture in a binding is missing a name + #[error("{0}: {1} - missing a name for the {2} capture")] + MissingCaptureName(PathBuf, String, String), + + /// A capture in a binding is missing a type + #[error("{0}: {1} - missing a type for the capture called {2}")] + MissingCaptureType(PathBuf, String, String), } /// A list of warnings. @@ -384,4 +428,14 @@ impl Warnings { pub fn warnings(&self) -> &[Warning] { &self.warnings } + + /// Is the underlying warning set empty? + pub fn is_empty(&self) -> bool { + self.warnings.is_empty() + } + + /// The number of warninings + pub fn len(&self) -> usize { + self.warnings.len() + } } |