Skip to main content

ErrorCode

Enum ErrorCode 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Trait Implementations§

Source§

impl Clone for ErrorCode

Source§

fn clone(&self) -> ErrorCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ErrorCode

Source§

impl Debug for ErrorCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ErrorCode

Source§

impl PartialEq for ErrorCode

Source§

fn eq(&self, other: &ErrorCode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ErrorCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.