pub enum DocumentError {
Show 19 variants
EmptyPath,
EmptyValues,
UnknownSegment {
path: String,
segment: String,
},
UnregisteredArray {
path: String,
},
SlugNotFound {
prefix: String,
slug: String,
},
AmbiguousMatch {
prefix: String,
segment: String,
indices: Vec<usize>,
},
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,
},
PathSyntax {
detail: String,
},
SourceRefused {
format: String,
detail: String,
},
InvalidArgument {
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
A non-numeric segment addressed an array that nothing claims: no
KeyedList registration covers it and its
format states no rule of its own.
The message names the two ways out rather than the internal type that happens to be missing — a caller can supply a rule or use an index, and neither is discoverable from the name of a Rust struct.
SlugNotFound
AmbiguousMatch
A non-numeric segment matched several elements of the array at prefix.
Substring matching can produce this, as can an explicit keyed-list field when an externally authored document contains duplicate identities. Naming several things at once is not an address, and picking the first would silently answer a different question than the one asked, so it is refused with structural candidate indices.
Candidate text is deliberately absent: an error must not become a route for document content to bypass normal output redaction.
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.
PathSyntax
A dot-path is malformed: a bad escape, a trailing \, a bare *, an
index past the platform’s range.
Distinct from Self::ParseError because nothing here came from the
document — the caller’s own address is what failed to parse, and
detail is afdata’s own words about it. Sharing a code with a rejected
file sent readers to inspect the wrong thing.
SourceRefused
afdata declines to read a source its parser would accept, because it cannot answer honestly about it.
detail is authored here and names the way out; it holds no document
text, so Self::redacted_message keeps it. Distinct from
Self::ParseError because the file is not malformed — reporting it as
a parse failure sends the reader hunting for a syntax error that is not
there.
InvalidArgument
A caller argument contradicts itself or the document. detail is
afdata’s own words about the argument, never document content.
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 share a code only when callers should handle them in
the same way. An ordinary missing path is document_path_not_found;
named array lookup distinguishes a missing slug from an ambiguous one.
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 can 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::PathSyntax, DocumentError::SourceRefused and
DocumentError::InvalidArgument keep their detail in full. It is the
reason they exist as separate variants: their text is written here, about
the caller’s address, argument, or file encoding — never lifted from
document content — and it is the only part that says what to do next.
Dropping it as a precaution against a leak that cannot happen turned an
actionable refusal into failed to parse Markdown.
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, requested slugs, indices, and type or format
names. In particular, Self::AmbiguousMatch carries candidate indices
rather than matched field values.
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()