Skip to main content

XmlError

Struct XmlError 

Source
pub struct XmlError {
    pub domain: ErrorDomain,
    pub level: ErrorLevel,
    pub code: ErrorCode,
    pub message: String,
    pub file: Option<String>,
    pub line: Option<u32>,
    pub column: Option<u32>,
    pub byte_offset: Option<u64>,
    pub xpath_code: Option<String>,
}
Expand description

A structured XML processing error.

SupXML returns XmlError through Result<_, XmlError> instead of relying on a global error variable like libxml2 does. The domain, level, and code fields let callers react without parsing the human-readable message.

code is an ErrorCode enum whose discriminants match libxml2’s xmlParserErrors numeric values. Callers can match on the enum (idiomatic Rust); the [crates/compat] cdylib converts to libxml2’s xmlError::code: i32 via err.code as i32 — zero cost. See thoughts/c_abi_implementation_plan.md for the design.

Fields§

§domain: ErrorDomain

Which subsystem produced the error.

§level: ErrorLevel

Severity.

§code: ErrorCode

Specific error category (libxml2-compatible numeric code on the wire side). When in doubt, ErrorCode::InternalError.

§message: String

Human-readable description of the problem.

§file: Option<String>

Source file name, if available (e.g. for file-based parsing).

§line: Option<u32>

1-based line number where the error occurred, if known.

§column: Option<u32>

1-based column number where the error occurred, if known.

§byte_offset: Option<u64>

0-based byte offset into the parser’s input buffer where the error occurred, if known.

Reported alongside line / column because the three answer different questions: line/col is what a human reads, byte offset is what tools (editors, LSP servers, dd if=… bs=1 skip=…) act on without re-walking the input. Byte offset also survives line-ending normalization (XML 1.0 § 2.11) and is the only useful coordinate for binary pipelines — gzipped XML, network captures, mmap’d files.

u64 (not usize) so that the ABI surface in crates/compat is stable across 32- and 64-bit targets and survives documents larger than 4 GB on the streaming reader.

§Coordinate system

The offset is measured in the parser’s internal UTF-8 buffer, which is the same as the caller’s input byte slice in the common case (input was already UTF-8). If ParseOptions::auto_transcode converted UTF-16 or another encoding to UTF-8 first, the offset is relative to the post-transcode buffer and does not point at the user’s original bytes; the user-facing offset would require a transcoder back-map we don’t have today. Callers operating on already-UTF-8 input — which is the overwhelming majority of XML on the wire — can use this directly.

§xpath_code: Option<String>

XPath/XQuery/XSLT error code as a local name in the standard err: namespace (http://www.w3.org/2005/xqt-errors) — e.g. "FOAR0001" for division by zero, "FORG0001" for an invalid cast. Distinct from code, which is the libxml2-numeric category; this is the spec-defined dynamic error a stylesheet’s xsl:catch / try/catch matches on and exposes through $err:code. None when the error has no specific spec code (it then projects as the generic err:FOER0000).

Implementations§

Source§

impl XmlError

Source

pub fn new( domain: ErrorDomain, level: ErrorLevel, message: impl Into<String>, ) -> Self

Construct an error with the catch-all ErrorCode::InternalError code. Add a more specific code via with_code when there’s a libxml2 numeric value that fits the case.

Source

pub fn with_code(self, code: ErrorCode) -> Self

Attach a specific ErrorCode (libxml2-numeric). Builder-style; returns self for chaining with at.

Source

pub fn with_xpath_code(self, code: impl Into<String>) -> Self

Attach the spec-defined XPath/XSLT error code (an err: local name such as "FOAR0001"). Builder-style; see xpath_code.

Source

pub fn or_xpath_code(self, code: impl Into<String>) -> Self

Attach code only if no spec code is already present. Used at outer choke points (e.g. document() retrieval) that want to label an otherwise-uncoded error without overwriting a more specific code an inner layer already set.

Source

pub fn at( self, file: impl Into<String>, line: u32, column: u32, byte_offset: u64, ) -> Self

Attach source position. All three coordinates are taken together because the scanner derives them from a single byte offset and any error that knows one knows all three; byte_offset is documented on Self::byte_offset.

Trait Implementations§

Source§

impl Clone for XmlError

Source§

fn clone(&self) -> XmlError

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 Debug for XmlError

Source§

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

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

impl Display for XmlError

Source§

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

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

impl Error for XmlError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<XmlError> for SchemaCompileError

Source§

fn from(e: XmlError) -> Self

Converts to this type from the input type.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.