#[non_exhaustive]pub enum MetadataError {
Show 13 variants
Parse {
format: FrontMatterFormat,
span: Option<Range<usize>>,
source: BoxedError,
},
ExtractionError {
message: String,
},
ProcessingError {
message: String,
},
MissingFieldError(String),
DateParseError(String),
IoError(Error),
YamlError(Error),
JsonError(Error),
TomlError(Error),
UnsupportedFormatError(String),
ValidationError {
field: String,
message: String,
},
Utf8Error(Utf8Error),
Other(BoxedError),
}Expand description
Custom error types for the metadata-gen library.
This enum encompasses all possible errors that can occur during metadata extraction, processing, and related operations.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Parse
A front-matter block was found but its parser rejected it.
span is the byte range inside the raw block the parser pointed
at, when it reported one (TOML and JSON always do; YAML reports
a line and column that are mapped to an offset). source is the
parser’s own error, reachable through Error::source.
Fields
format: FrontMatterFormatWhich parser rejected the block.
source: BoxedErrorThe parser’s error.
ExtractionError
Error occurred while extracting metadata.
ProcessingError
Error occurred while processing metadata.
MissingFieldError(String)
Error occurred due to missing required field.
DateParseError(String)
Error occurred while parsing date.
IoError(Error)
std only.I/O error.
YamlError(Error)
yaml only.YAML parsing error.
JsonError(Error)
json only.JSON parsing error.
TomlError(Error)
toml only.TOML parsing error.
UnsupportedFormatError(String)
Unsupported metadata format error.
ValidationError
Validation error for metadata fields.
Fields
Utf8Error(Utf8Error)
never produced by the crate; match on IoError for invalid UTF-8 from a reader
UTF-8 decoding error.
No function in the crate returns it: every entry point takes
&str, and the readers in metadata_gen::io report invalid UTF-8 as
an I/O error. Kept for code that matches on it or converts a
core::str::Utf8Error with ?.
Other(BoxedError)
Catch-all for unexpected errors.
There is deliberately no From<BoxedError>: a boxed error never
becomes a MetadataError by accident through ?. Build it with
MetadataError::other where the coercion is intended.
Implementations§
Source§impl MetadataError
impl MetadataError
Sourcepub fn other<E>(error: E) -> Self
pub fn other<E>(error: E) -> Self
Wraps any error as MetadataError::Other.
§Example
use metadata_gen::error::MetadataError;
let err = MetadataError::other(core::fmt::Error);
assert!(matches!(err, MetadataError::Other(_)));Sourcepub fn new_extraction_error(message: impl Into<String>) -> Self
pub fn new_extraction_error(message: impl Into<String>) -> Self
Creates a new ExtractionError with the given message.
§Arguments
message- A descriptive message about the extraction error.
§Returns
A new MetadataError::ExtractionError variant.
§Example
use metadata_gen::error::MetadataError;
let error = MetadataError::new_extraction_error("Failed to extract title");
assert!(matches!(error, MetadataError::ExtractionError { .. }));Sourcepub fn new_processing_error(message: impl Into<String>) -> Self
pub fn new_processing_error(message: impl Into<String>) -> Self
Creates a new ProcessingError with the given message.
§Arguments
message- A descriptive message about the processing error.
§Returns
A new MetadataError::ProcessingError variant.
§Example
use metadata_gen::error::MetadataError;
let error = MetadataError::new_processing_error("Failed to process metadata");
assert!(matches!(error, MetadataError::ProcessingError { .. }));Sourcepub fn new_validation_error(
field: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn new_validation_error( field: impl Into<String>, message: impl Into<String>, ) -> Self
Creates a new ValidationError with the given field and message.
§Arguments
field- The name of the field that failed validation.message- A descriptive message about the validation error.
§Returns
A new MetadataError::ValidationError variant.
§Example
use metadata_gen::error::MetadataError;
let error = MetadataError::new_validation_error("title", "Title must not be empty");
assert!(matches!(error, MetadataError::ValidationError { .. }));Sourcepub fn context<C>(self, ctx: C) -> Self
pub fn context<C>(self, ctx: C) -> Self
Adds context to an existing error.
This method wraps the current error with additional context information.
§Arguments
ctx- The context to add to the error.
§Returns
A new MetadataError with the added context.
§Example
use metadata_gen::error::MetadataError;
let error = MetadataError::new_extraction_error("Failed to parse YAML")
.context("Processing file 'example.md'");
assert_eq!(error.to_string(), "Failed to extract metadata: Processing file 'example.md': Failed to parse YAML");Trait Implementations§
Source§impl Debug for MetadataError
impl Debug for MetadataError
Source§impl Display for MetadataError
impl Display for MetadataError
Source§impl Error for MetadataError
impl Error for MetadataError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()