summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs84
1 files changed, 59 insertions, 25 deletions
diff --git a/src/error.rs b/src/error.rs
index a729bf0..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,10 +10,18 @@ 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}")]
BindingsFileNotFound(PathBuf, #[source] std::io::Error),
@@ -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,
@@ -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,10 +306,6 @@ 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),
@@ -306,10 +314,6 @@ pub enum SubplotError {
#[error("Failed to parse YAML metadata in {0}")]
MetadataFile(PathBuf, #[source] serde_yaml::Error),
- /// Abstract syntax tree error.
- #[error(transparent)]
- Ast(#[from] crate::ast::Error),
-
/// UTF8 conversion error.
#[error("failed to parse UTF8 in file {0}")]
FileUtf8(PathBuf, #[source] std::string::FromUtf8Error),
@@ -318,6 +322,10 @@ pub enum SubplotError {
#[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),
@@ -329,6 +337,10 @@ pub enum SubplotError {
/// 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 {
@@ -378,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.
@@ -404,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()
+ }
}