Expand description
Error subsystem (§21, §85 Phase 1).
Implements the libxml2 error reporting infrastructure:
xmlErrorstruct management- Error domain/code registry
- Structured error callbacks (thread-local storage)
- Generic error callbacks (thread-local storage)
- Last-error tracking (thread-local
xmlGetLastError,xmlResetLastError,xmlCopyError) - Error message formatting
xmlRaiseError()— the central error reporting function
§UPSTREAM-PARITY
libxml2 has a two-tier error system:
-
Structured errors —
xmlStructuredErrorFuncreceives anxmlErrorPtrwith all structured fields (domain, code, level, line, etc.) -
Generic errors —
xmlGenericErrorFuncreceives a formatted string (printf-style). This is the older system, still widely used.
Both systems coexist. When both handlers are set, both are called.
The last error is stored thread-locally for retrieval via xmlGetLastError.
§Phase 1 status
Complete — all error functions are implemented. Variadic message formatting will be enhanced in Phase 2+.
§Upstream contract
Mirrors upstream error.c (SRC-LIBXML2-2.15.0-ERROR-C, oracle tree
oracle/historical/src/libxml2-2.15.0/error.c): xmlRaiseError /
xmlVRaiseError routing, xmlFormatError, xmlGenericErrorDefaultFunc,
xmlGetLastError / xmlCtxtGetLastError / xmlResetLastError, xmlCopyError
and the legacy xmlParserError / xmlParserWarning SAX handlers.
§Conceptual behavior
Two-tier error system: structured errors (xmlStructuredErrorFunc with the full xmlError) and generic errors (printf-style fragments). The 11.1-M/K rework routes each raise through ONE channel: a structured handler, else the custom SAX channel (channel(data, msg) once), else the legacy default streaming the xmlFormatError fragments (file/line, domain, level, message, source window, caret) as 6 variadic calls (R-000161).
§Ownership & safety invariants
Ownership: the thread-local last error owns its file/str1-3 copies; raise_error_streamed copies transient CStrings (R-000163: dangling pointers were the bug). The exported xmlLastError mirror is synced under lock (R-000170). SAFETY: the variadic xmlGenericErrorDefaultFunc and xmlParserError legacy handlers are x86_64 SysV inline-asm va_list shims — stable Rust cannot define variadic extern fns.
§Historical quirks & epochs
E-005: fatal parser errors are reported twice from 2.13.0 (attr-markup- entity); the xmlFormatError fragment stream and the 80-column source window cap are 2.15 semantics (xmlParserInputGetWindow, caret clamp). R-000163 pinned all XML_ERR_* 64-96 constants to upstream numbering (SPACE_REQUIRED 65, NAME_REQUIRED 68, GT_REQUIRED 73, TAG_NAME_MISMATCH 76, TAG_NOT_FINISHED 77 — not the synthetic renumbering).
§Deliberate oddities
Deliberate oddities: warnings only bump nbWarnings while other levels update errNo / nbErrors / wellFormed per xmlCtxtVErr; the source window replicates the 80-char cap, continuation-byte skip, UTF-8 forward scan and the 2.15 caret clamp (col >= n maps to size-1).
§Proving courts
ERROR and CALLBACK court families; ERROR-001 (48 deterministic malformed
inputs x 4 passes, byte-identical), GLOBALS-THREADING, DATA-GLOBALS-001,
and cargo test --lib (ASan-clean).
§Tempting simplifications that would break parity
The tempting simplification is one generic call plus a direct stderr write — a counting handler would observe 1 call instead of the 6 xmlFormatError fragments the oracle emits (R-000161). Do not route errors to stderr when a handler is installed. Never renumber the XML_ERR_* constants (R-000163).
Enums§
- Generic
Delivery - How a raise delivers to the generic side of the error system (upstream
xmlVRaiseErrorchannel selection, error.c 2.15).
Functions§
- copy_
error ⚠ - Copy an error from one location to another.
- format_
error_ message - Format an error message.
- get_
last_ error - Get the last error for the current thread.
- raise_
error ⚠ - Raise an error — the central error reporting function.
- raise_
error_ ⚠streamed - Raise an error with upstream’s full routing (error.c 2.15
xmlVRaiseError): update the last error, then deliver to the structured handler or the selected generic channel — never both. - reset_
error ⚠ - Reset an error structure to its default state.
- reset_
last_ error - Reset the last error for the current thread.
- set_
generic_ ⚠error_ func - Set the generic error handler.
- set_
structured_ ⚠error_ func - Set the structured error handler.
- xmlParser
Error ⚠ - Default SAX v1 error handler —
void xmlParserError(void *ctx, const char *msg, ...). - xmlParser
Validity ⚠Error - Default validity error handler —
void xmlParserValidityError(void *ctx, const char *msg, ...). - xmlParser
Validity ⚠Warning - Default validity warning handler —
void xmlParserValidityWarning(void *ctx, const char *msg, ...). - xmlParser
Warning ⚠ - Default SAX v1 warning handler —
void xmlParserWarning(void *ctx, const char *msg, ...).