#[non_exhaustive]pub enum EditError {
InvalidFieldName(String),
UnknownField(String),
InvalidKindName(String),
ReservedKind,
IndexOutOfRange {
index: usize,
len: usize,
},
ValueTooDeep {
max: usize,
},
Import(ImportError),
FieldDecode {
field: String,
codec: String,
message: String,
},
FieldNotContent {
field: String,
declared: String,
},
FieldNotInline {
field: String,
codec: String,
},
FieldCoercionFailed {
field: String,
target: String,
message: String,
},
ContentApply(ApplyError),
}Expand description
Errors returned by document and card mutators.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidFieldName(String)
UnknownField(String)
A typed write (TypedWriter::set /
CardWriter::set) addressed a well-formed name
that the bound schema does not declare (or a card whose $kind carries
no schema). The typed path resolves every name to a schema type, so an
undeclared name is a typo, not a fallback: it fails here instead of
landing silently in the opaque store. Reach for the raw
Card::store_field when opaque storage is the intent.
InvalidKindName(String)
ReservedKind
IndexOutOfRange
ValueTooDeep
Import(ImportError)
Markdown import failed: the content codec rejected the input for a body
or a field path (e.g. container nesting past
MAX_NESTING_DEPTH). Returned
instead of silently degrading the target to empty on a rejected import.
FieldDecode
A value could not become the field’s content through codec: a JSON
object that is not a canonical content, a markdown string that failed to
import, a shape that is neither object nor string, or formatting under
the plain-only plaintext codec. message names which, as engine prose
riding no arg. Returned by Card::commit_field on
a content field, by Card::revise_field on a
present non-content field, and by the reads on
TypedReader.
codec is the declared type’s, not the stored shape’s: the same bytes
decode two ways and only the schema says which ran.
Absence is not this error. A missing field is None everywhere the API
meets one, and the content lane reads it as the empty content.
Fields
codec: StringThe codec that ran, named by the field’s declared type:
CODEC_RICHTEXT or CODEC_PLAINTEXT.
FieldNotContent
A Content read (TypedReader::get_content)
addressed a field whose declared type is not a content leaf. Which codec
decodes a value is a property of the declared type, not of the stored
shape, so the schema answers this before the payload is consulted: an
integer field has no Content to return even when it happens to hold a
string.
The condition is a leaf one, narrower than the subtree test conform
walks (field_contains_content): an array<richtext> carries content and
still has no one Content, so it lands here. Read its elements through
get.
FieldNotInline
A content field written under an inline: true schema decoded to a
multi-line content: the write-time counterpart of the
coercion/validation inline check, raised by
Card::commit_field. Both prose codecs declare
inline, so one code covers both and codec says which lane it came
from.
Fields
codec: StringThe codec whose inline constraint was violated: CODEC_RICHTEXT
or CODEC_PLAINTEXT.
FieldCoercionFailed
A typed write (Card::commit_field) could not
coerce the value to the field’s schema type: the general write-commit
failure for scalar/array/object types (a "x" for an integer, a
non-object for an object, …). The mutator-plane twin of
validation::coercion_failed, minted from the same CoercionError.
Content fields report through the dedicated
FieldDecode / FieldNotInline
variants instead.
Fields
target: StringThe schema type the write was coerced against, carried across
from CoercionError so the failure
states what the value had to become. message alone is English.
ContentApply(ApplyError)
A content field-change bundle (text delta, line ops, mark ops) applied out of bounds or broke an invariant normalization could not repair.
Implementations§
Source§impl EditError
impl EditError
Sourcepub fn code(&self) -> &'static str
pub fn code(&self) -> &'static str
The namespaced diagnostic code (e.g. "edit::invalid_field_name"),
one per variant, and the variant’s only stable discriminator. This is
the machine-routable identity both bindings stamp onto the Diagnostic
they raise: the edit::* peer of parse::*, validation::*, and the
rest of the taxonomy in prose/canon/ERROR.md. Consumers route on this,
not on message text; a Rust caller matching the enum has
#[non_exhaustive] to answer to and a _ arm regardless.
Sourcepub fn args(&self) -> BTreeMap<String, Value>
pub fn args(&self) -> BTreeMap<String, Value>
The facts this error’s message interpolates. See
Diagnostic::args; ERROR.md
§ “Diagnostic args” says per code whether an empty map means a fixed
sentence or a fallback to message.
field and kind ride here despite doc_path also
folding them into the anchor. The rule against duplicating an anchor
bars the assembled path string, and recovering a name from one is
unsound anyway: DocPath renders field
segments unescaped and parses on . and [, so exactly the malformed
names InvalidFieldName reports can round-trip into other segments.
Sourcepub fn doc_path(&self, base: &DocPath) -> Option<DocPath>
pub fn doc_path(&self, base: &DocPath) -> Option<DocPath>
The DocPath this error anchors to, relative to
base, the card root the mutator ran against (main for a main-card
mutator, cards.<kind>[i] for a composable card, cards[i] for a
structural op on the array; empty only for a card built before it is
placed, which has no index yet).
A field-named variant anchors at its field under base
(main.<field>, cards.<kind>[i].<field>, or a bare <field> when
base is empty: the pre-placement card);
IndexOutOfRange at the document-array slot
cards[index], base-independent: a structural op names a slot, not a
field; and the remaining variants (kind errors, depth, content
apply/import) anchor at base itself when it names a card, else carry no
anchor (a config-space $seed error keeps an empty base). Both
bindings route through this so a mutator diagnostic is addressable the
same way a validation diagnostic is.
Trait Implementations§
Source§impl Error for EditError
impl Error for EditError
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()