#[non_exhaustive]pub enum Error {
Show 20 variants
ContentTooLarge {
size: usize,
max: usize,
},
NestingTooDeep {
depth: usize,
max: usize,
},
YamlParseError {
source: Arc<Error>,
},
TomlParseError(Error),
JsonParseError(Arc<Error>),
InvalidFormat,
ConversionError(String),
ParseError(String),
UnsupportedFormat {
line: usize,
},
NoFrontmatterFound,
InvalidJson,
InvalidUrl(String),
InvalidToml,
InvalidYaml,
InvalidLanguage(String),
JsonDepthLimitExceeded,
ExtractionError(String),
SerdeError {
source: Arc<Error>,
},
ValidationError(String),
Other(String),
}
Expand description
Represents errors that can occur during front matter operations.
This enumeration uses the thiserror
crate to provide structured error
messages, improving the ease of debugging and handling errors encountered
in front matter processing.
Each variant represents a specific type of error that may occur during front matter operations, with appropriate context and error details.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ContentTooLarge
Content exceeds the maximum allowed size.
This error occurs when the content size is larger than the configured maximum limit.
§Fields
size
- The actual size of the contentmax
- The maximum allowed size
NestingTooDeep
Nesting depth exceeds the maximum allowed.
This error occurs when the structure’s nesting depth is greater than the configured maximum depth.
YamlParseError
Error occurred whilst parsing YAML content.
This error occurs when the YAML parser encounters invalid syntax or structure.
TomlParseError(Error)
Error occurred whilst parsing TOML content.
This error occurs when the TOML parser encounters invalid syntax or structure.
JsonParseError(Arc<Error>)
Error occurred whilst parsing JSON content.
This error occurs when the JSON parser encounters invalid syntax or structure.
InvalidFormat
The front matter format is invalid or unsupported.
This error occurs when the front matter format cannot be determined or is not supported by the library.
ConversionError(String)
Error occurred during conversion between formats.
This error occurs when converting front matter from one format to another fails.
ParseError(String)
Generic error during parsing.
This error occurs when a parsing operation fails with a generic error.
UnsupportedFormat
Unsupported or unknown front matter format was detected.
This error occurs when an unsupported front matter format is encountered at a specific line.
NoFrontmatterFound
No front matter content was found.
This error occurs when attempting to extract front matter from content that does not contain any front matter section.
InvalidJson
Invalid JSON front matter.
This error occurs when the JSON front matter is malformed or invalid.
InvalidUrl(String)
Invalid URL format.
This error occurs when an invalid URL is encountered in the front matter.
InvalidToml
Invalid TOML front matter.
This error occurs when the TOML front matter is malformed or invalid.
InvalidYaml
Invalid YAML front matter.
This error occurs when the YAML front matter is malformed or invalid.
InvalidLanguage(String)
Invalid language code.
This error occurs when an invalid language code is encountered in the front matter.
JsonDepthLimitExceeded
JSON front matter exceeds maximum nesting depth.
This error occurs when the JSON front matter structure exceeds the maximum allowed nesting depth.
ExtractionError(String)
Error during front matter extraction.
This error occurs when there is a problem extracting front matter from the content.
SerdeError
Serialization or deserialization error.
This error occurs when there is a problem serializing or deserializing content.
ValidationError(String)
Input validation error.
This error occurs when the input fails validation checks.
Other(String)
Generic error with a custom message.
This error occurs when a generic error is encountered with a custom message.
Implementations§
Source§impl Error
impl Error
Sourcepub fn generic_parse_error(message: &str) -> Self
pub fn generic_parse_error(message: &str) -> Self
Sourcepub const fn unsupported_format(line: usize) -> Self
pub const fn unsupported_format(line: usize) -> Self
Sourcepub fn validation_error(message: &str) -> Self
pub fn validation_error(message: &str) -> Self
Sourcepub fn with_context(self, context: &Context) -> Self
pub fn with_context(self, context: &Context) -> Self
Adds context to an error.
§Arguments
context
- Additional context information about the error.
§Examples
use frontmatter_gen::error::{Error, Context};
let context = Context {
line: Some(42),
column: Some(10),
snippet: Some("invalid content".to_string()),
};
let error = Error::ParseError("Invalid syntax".to_string())
.with_context(&context);
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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
Source§impl From<EngineError> for Error
Converts an EngineError
into an Error
.
impl From<EngineError> for Error
Converts an EngineError
into an Error
.
This allows engine errors to be converted into front matter errors when needed, preserving the error context and message.
§Examples
use frontmatter_gen::error::{EngineError, Error};
use std::io;
let engine_error = EngineError::ContentError("content processing failed".to_string());
let frontmatter_error: Error = engine_error.into();
assert!(matches!(frontmatter_error, Error::ParseError(_)));