diff options
author | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2022-08-13 16:20:34 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers+gitlab@digital-scurf.org> | 2022-08-13 16:20:34 +0000 |
commit | e90337da2b293eb0111e6be9131ef2f25e861b9c (patch) | |
tree | 22550622adb354a345849f9402ea9299ac4199dc | |
parent | ac09169b21d94841eb45736c3ef937ce21283279 (diff) | |
parent | 9b3b0087512614d13e8c3b950041101ab649b786 (diff) | |
download | subplot-e90337da2b293eb0111e6be9131ef2f25e861b9c.tar.gz |
Merge branch 'liw/refactor-errors' into 'main'
feat: make errors have a source error
See merge request subplot/subplot!284
-rw-r--r-- | src/bin/subplot.rs | 13 | ||||
-rw-r--r-- | src/error.rs | 18 | ||||
-rw-r--r-- | subplot.md | 6 |
3 files changed, 20 insertions, 17 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs index e9cb00a..5e802b4 100644 --- a/src/bin/subplot.rs +++ b/src/bin/subplot.rs @@ -504,13 +504,6 @@ fn load_linted_doc( Ok(doc) } -fn print_source_errors(e: Option<&dyn std::error::Error>) { - if let Some(e) = e { - error!("{}", e); - print_source_errors(e.source()); - } -} - fn real_main() { info!("Starting Subplot"); let argparser = Toplevel::command(); @@ -525,7 +518,11 @@ fn real_main() { } Err(e) => { error!("{}", e); - print_source_errors(e.source()); + let mut e = e.source(); + while let Some(source) = e { + error!("caused by: {}", source); + e = source.source(); + } process::exit(1); } } diff --git a/src/error.rs b/src/error.rs index 8236faf..17870c5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,12 +13,12 @@ pub enum SubplotError { 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), + #[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")] @@ -201,7 +201,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 +233,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}")] @@ -302,6 +302,10 @@ pub enum SubplotError { #[error("Failed to parse YAML metadata")] Metadata(#[source] serde_yaml::Error), + /// Error parsing YAML metadata for document, from external file. + #[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), @@ -2399,7 +2399,8 @@ given file missing-binding.md and an installed subplot when I try to run subplot docgen missing-binding.md -o foo.html then command fails -and stderr contains ": missing-binding.yaml:" +and stderr contains "could not be found" +and stderr contains "missing-binding.yaml" ~~~ ~~~{#missing-binding.md .file .markdown .numberLines} @@ -2420,7 +2421,8 @@ and file b.yaml and an installed subplot when I try to run subplot codegen --run missing-functions.md -o foo.py then command fails -and stderr contains ": missing-functions.py:" +and stderr contains "could not be found" +and stderr contains "missing-functions.py" ~~~ ~~~{#missing-functions.md .file .markdown .numberLines} |