pub enum DocumentError {
Show 15 variants
EmptyPath,
EmptyValues,
UnknownSegment {
path: String,
segment: String,
},
UnregisteredArray {
path: String,
},
SlugNotFound {
prefix: String,
slug: String,
},
SlugAlreadyExists {
prefix: String,
slug: String,
},
NotTraversable {
path: String,
got: String,
},
TypeMismatch {
path: String,
expected: String,
got: String,
hint: Option<String>,
},
PathNotFound {
path: String,
},
IndexOutOfBounds {
path: String,
index: usize,
len: usize,
},
ParseError {
format: String,
detail: String,
},
WriteWouldCorrupt {
format: String,
detail: String,
},
FormatUnknown {
path: String,
},
IoError {
detail: String,
},
UnsupportedOperation {
format: String,
operation: String,
detail: String,
},
}Variants§
EmptyPath
EmptyValues
UnknownSegment
UnregisteredArray
SlugNotFound
SlugAlreadyExists
NotTraversable
TypeMismatch
PathNotFound
IndexOutOfBounds
ParseError
A parser rejected the source. detail is the parser’s own text, which
quotes the offending line — see Self::redacted_message.
WriteWouldCorrupt
A staged edit rendered source this format’s own parser rejects, caught
by the read-back in save_atomic before any bytes reached disk.
detail is already redacted: it comes from
Self::redacted_message of the rejection, not from its Display.
FormatUnknown
No format could be inferred for path, so nothing was parsed at all.
Distinct from Self::ParseError because it is about the file’s name,
never its contents: it carries no document text, and dropping its detail
as a precaution would throw away the only actionable thing it says.
IoError
UnsupportedOperation
Implementations§
Source§impl DocumentError
impl DocumentError
Sourcepub const fn code(&self) -> &'static str
pub const fn code(&self) -> &'static str
Stable, program-decidable error code for this failure category.
Multiple variants can share a code when callers should handle them in
the same way. In particular, all read-address failures report
document_path_not_found.
Sourcepub fn location(&self) -> Option<String>
pub fn location(&self) -> Option<String>
Best-effort, content-free source location for a parse failure.
Returns e.g. "line 5 column 12" (or "line 5") for a
DocumentError::ParseError, and None for every other variant or
when the underlying parser reported no position. The returned string is
derived from the parser’s position only and never contains document
content, so it is safe to surface even when the parsed file may hold
secrets.
Sourcepub fn redacted_message(&self) -> String
pub fn redacted_message(&self) -> String
A display message with any potentially content-bearing detail removed — safe to surface when the document may hold secrets.
Two variants quote material that originates in the document and are rewritten here:
DocumentError::ParseErrorrenders asfailed to parse {format}(with thelocationappended when known), dropping the parser detail, which echoes a snippet of the source.DocumentError::TypeMismatchdropsgotandhint. When built bySelf::from_serdethose carry serde’s rendering of the offending value, which is document content.
Every other variant renders the same as its [Display], carrying only
structural context: paths, slugs, indices, and type or format names.
DocumentError::NotTraversable belongs to that group because got is
a Value::kind_name, not a value.
Sourcepub fn from_serde(path: impl Into<String>, err: impl Display) -> Self
pub fn from_serde(path: impl Into<String>, err: impl Display) -> Self
Wrap a serde deserialization failure as a TypeMismatch so callers that
do a read-modify-write cycle (set_path → serde round-trip) surface a
consistent error style rather than a raw serde message.
Trait Implementations§
Source§impl Clone for DocumentError
impl Clone for DocumentError
Source§fn clone(&self) -> DocumentError
fn clone(&self) -> DocumentError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DocumentError
impl Debug for DocumentError
Source§impl Display for DocumentError
impl Display for DocumentError
Source§impl Error for DocumentError
impl Error for DocumentError
1.30.0 · 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()