Skip to main content

MetadataError

Enum MetadataError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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: FrontMatterFormat

Which parser rejected the block.

§span: Option<Range<usize>>

Byte range inside the raw front-matter block, if the parser gave one.

§source: BoxedError

The parser’s error.

§

ExtractionError

Error occurred while extracting metadata.

Fields

§message: String

A descriptive message about the extraction error.

§

ProcessingError

Error occurred while processing metadata.

Fields

§message: String

A descriptive message about the processing error.

§

MissingFieldError(String)

Error occurred due to missing required field.

§

DateParseError(String)

Error occurred while parsing date.

§

IoError(Error)

Available on crate feature std only.

I/O error.

§

YamlError(Error)

Available on crate feature yaml only.

YAML parsing error.

§

JsonError(Error)

Available on crate feature json only.

JSON parsing error.

§

TomlError(Error)

Available on crate feature toml only.

TOML parsing error.

§

UnsupportedFormatError(String)

Unsupported metadata format error.

§

ValidationError

Validation error for metadata fields.

Fields

§field: String

The field that failed validation.

§message: String

A descriptive message about the validation error.

§

Utf8Error(Utf8Error)

👎Deprecated since 0.0.8:

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

Source

pub fn other<E>(error: E) -> Self
where E: Error + Send + Sync + 'static,

Wraps any error as MetadataError::Other.

§Example
use metadata_gen::error::MetadataError;

let err = MetadataError::other(core::fmt::Error);
assert!(matches!(err, MetadataError::Other(_)));
Source

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 { .. }));
Source

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 { .. }));
Source

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 { .. }));
Source

pub fn context<C>(self, ctx: C) -> Self
where C: Display + Send + Sync + 'static,

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MetadataError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for MetadataError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for MetadataError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for MetadataError

Source§

fn from(source: SerdeYmlError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for MetadataError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for MetadataError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Utf8Error> for MetadataError

Source§

fn from(source: Utf8Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.