diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-08-13 19:03:37 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-08-13 19:03:37 +0300 |
commit | 9b3b0087512614d13e8c3b950041101ab649b786 (patch) | |
tree | 8dbf69f30988038b9907cd2462790ee2d3790fb3 /src/error.rs | |
parent | 60b5a9a313bec0a6e475f9c16380977ed1c7eafb (diff) | |
download | subplot-9b3b0087512614d13e8c3b950041101ab649b786.tar.gz |
feat: make errors have a source error
When errors have a source, i.e., an underlying error, it results in
better error messages to the user.
Also, refactor the way the source chain is printed, to code that is
clearer to me.
I will need this to for loading document metadata from an external
YAML file.
Sponsored-by: author
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/error.rs b/src/error.rs index a42298d..d714d21 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), |