#[non_exhaustive]#[repr(i32)]pub enum ErrorCode {
Show 33 variants
Ok = 0,
InternalError = 1,
NoMemory = 2,
DocumentEmpty = 4,
InvalidHexCharRef = 6,
InvalidDecCharRef = 7,
InvalidChar = 9,
UndeclaredEntity = 26,
UnknownEncoding = 31,
UnsupportedEncoding = 32,
AttributeRedefined = 42,
CommentNotFinished = 45,
XmlDeclNotStarted = 56,
XmlDeclNotFinished = 57,
MisplacedCdataEnd = 62,
CdataNotFinished = 63,
NameRequired = 68,
EqualRequired = 75,
TagNameMismatch = 76,
TagNotFinished = 77,
NotWellBalanced = 85,
ExtraContent = 86,
NsErrUndefinedNamespace = 201,
NsErrQname = 202,
IoLoadError = 1_549,
SchemavCvcDatatypeValid121 = 1_824,
SchemavCvcFacetValid = 1_829,
SchemavCvcComplexType322 = 1_867,
SchemavCvcComplexType4 = 1_868,
SchemavElementContent = 1_871,
DtdNotEmpty = 528,
RelaxngErrElemwrong = 38,
EncodingConvFailed = 6_003,
}Expand description
One of libxml2’s well-known numeric error codes.
libxml2’s xmlParserErrors enum has ~800 variants; this type covers
the ~40 we actually emit from the parser, validator, encoder, etc.
Everything else lands at ErrorCode::InternalError (= 1), which
is what libxml2 itself uses for unmapped cases.
Discriminants are pinned to match libxml2’s include/libxml/xmlerror.h
exactly — do not renumber. A C caller doing
if (err->code == XML_ERR_INVALID_CHAR) { ... } sees 9 here too,
because ErrorCode::InvalidChar as i32 == 9.
§When to add a new variant
When you have a new error-construction site that maps to a specific
libxml2 code that callers genuinely check for. When in doubt, default
to ErrorCode::InternalError. Adding a variant is additive (callers
reading numeric codes are unaffected) but renumbering an existing
variant is a breaking ABI change.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ok = 0
No error — round-trip sentinel. We don’t emit this from Rust.
InternalError = 1
Default for any error we can’t classify more specifically. libxml2 itself uses this for unhandled cases, so callers branching on specific codes will already have a “default” arm that handles us.
NoMemory = 2
Out-of-memory at parse / build time. Not currently emitted (we panic on OOM today), reserved for when we add fallible alloc.
DocumentEmpty = 4
Document is empty (no root element, no prolog).
InvalidHexCharRef = 6
&#x...; malformed — empty hex, non-hex digit, etc.
InvalidDecCharRef = 7
&#...; malformed — empty decimal, non-digit, etc.
InvalidChar = 9
Character outside XML 1.0 § 2.2 char range.
UndeclaredEntity = 26
Entity reference to an undeclared entity name.
UnknownEncoding = 31
Unknown encoding label on <?xml encoding="..."?> or BOM mismatch.
UnsupportedEncoding = 32
Encoding declared but not supported by the build.
AttributeRedefined = 42
Two attributes with the same expanded name on one element.
CommentNotFinished = 45
Comment didn’t terminate before EOF.
XmlDeclNotStarted = 56
Bad <?xml ... ?> declaration syntax.
XmlDeclNotFinished = 57
MisplacedCdataEnd = 62
]]> in text content, where it’s reserved for CDATA close.
CdataNotFinished = 63
CDATA section didn’t terminate before EOF.
NameRequired = 68
Expected an XML name (start tag, attribute name, entity name, etc.).
EqualRequired = 75
Expected = after attribute name.
TagNameMismatch = 76
</X> end-tag name doesn’t match the open <Y>.
TagNotFinished = 77
Start tag never closed before EOF.
NotWellBalanced = 85
Document is not well-balanced (open tags don’t match close tags at EOF). General catch-all when we can’t say which tag.
ExtraContent = 86
Content after the root element’s close.
NsErrUndefinedNamespace = 201
Prefix used but never declared via xmlns:prefix=....
NsErrQname = 202
Malformed QName (e.g. multiple colons).
IoLoadError = 1_549
A document input (the main file or an external entity) could not
be opened or read. libxml2’s __xmlLoaderErr reports exactly
this code with domain ErrorDomain::Io; consumers that key on
the domain (e.g. lxml’s _raiseParseError) then raise an I/O
error rather than a syntax error.
SchemavCvcDatatypeValid121 = 1_824
Attribute/element value invalid against its datatype.
SchemavCvcFacetValid = 1_829
A value rejected by a facet (pattern, length, range, …).
SchemavCvcComplexType322 = 1_867
An attribute not permitted by the element’s complex type.
SchemavCvcComplexType4 = 1_868
A required attribute is missing.
SchemavElementContent = 1_871
Element content doesn’t match the declared content model (unexpected child element, or a required one absent).
DtdNotEmpty = 528
An element declared EMPTY has child content.
RelaxngErrElemwrong = 38
An element appeared where the pattern did not expect it.
EncodingConvFailed = 6_003
Encoding handler couldn’t decode the input bytes.