Expand description
XSLT error handling (§33, §85 Phase 8).
Defines error domains, error levels, error handler types, and the public API for reporting and retrieving XSLT errors.
§Upstream contract
Parity target: upstream libxslt xsltutils.c + xsltInternals.h
(1.1.45; SRC-LIBXSLT-1.1.42-XSLTUTILS-C under oracle/historical/src).
The observable surface is xsltTransformError (with its
xsltPrintErrorContext context line), xsltSetTransformErrorFunc,
xsltSetGenericDebugFunc/xsltGenericDebug, xsltGetLastError, and
the XSLT_ERR_* domain/level constants from xslt.h 1.1.45.
§Conceptual behavior
Error reporting follows upstream routing: xsltTransformError moves
the transform context out of the OK state (error or stopped), prints
the xsltPrintErrorContext context line (one of error,
compilation error, runtime error, each optionally with file/line/
element), and emits the message verbatim — messages carry their own
trailing newline and the function is variadic upstream, so callers
format before calling (the candidate never expands %s/%d
placeholders). With a registered per-context handler the message is
routed there; otherwise it goes to stderr.
§Ownership & safety invariants
LAST_XSLT_ERRORis a mutex-guarded thread-safe copy of the last raw message;xsltGetLastErrorreturns a heap copy the caller frees with libc::free (matching the documentedcaller freescontract forxsltGetLastError).- Handler slots (
error/errctx) are borrowed user-data, never dereferenced by the library — per atlas/OWNERSHIP_ATLAS.md section 6, the caller keeps the context alive. - The exported
xsltGenericDebug/xsltGenericDebugContextdata globals (crate::abi::data_globals) are process-global, exactly like the upstreamxsltGenericDebugglobals; callers must not race them (R-000171 slot-race lesson applied to the debug pair). 11.1-Z.1:xsltGenericDebugis exported as DATA (function pointer, oracle D) with the upstream default handler, not as a function (R-000174).
§Historical quirks & epochs
E-008 (atlas/SEMANTIC_EPOCHS.md): error output participates in the
byte-identical xsltproc epoch (1.1.26, 2009, through 1.1.45), so the
context-line wording is frozen. R-000161 fixed error routing parity for
the generic/structured handler chain (xmlFormatError fragment
streaming, 6 calls per raise) and the default variadic stderr printers
xmlGenericError/xsltGenericError; the candidate xsltGenericDebug
default handler writes through the xsltGenericDebugContext FILE* with
the upstream NULL-context suppression (11.1-Z.1, R-000174).
R-000140 covered the _xslt* ABI mirrors.
§Deliberate oddities
- The variadic upstream signature is reduced to a pre-formatted
message (an intentional, documented divergence — see the
xsltTransformErrordocs); the emitted bytes match the oracle. xsltSetGenericDebugFunckeeps the upstream NULL-context suppression quirk: a NULL handler with a NULL context suppresses debug output.
§Proving courts
ERROR-001 (error-family differential probe; R-000161), CLI-XSLTPROC
(stderr byte-compare on failing stylesheets), XSLT-001, and the
in-crate cargo test suites.
§Tempting simplifications that would break parity
- Replacing the context line with a plain
error:prefix breaks stderr byte-parity for compilation and runtime errors (thexsltPrintErrorContextforms are oracle-verified). - Buffering the last-error message with the error state would drop the
frozen
statetransition (OK → ERROR/STOPPED) that the transform loop checks to stop execution. - Writing debug output unconditionally would break the upstream NULL-context suppression contract exercised by the CLI corpus.
Constants§
- XSLT_
ERR_ CYCLIC_ REFERENCE - Cyclic reference detected.
- XSLT_
ERR_ INTERNAL - Internal XSLT error.
- XSLT_
ERR_ INVALID_ ATTRIBUTE - Invalid attribute value.
- XSLT_
ERR_ INVALID_ ELEMENT - Invalid element.
- XSLT_
ERR_ INVALID_ MATCH - Invalid match pattern.
- XSLT_
ERR_ INVALID_ NAMESPACE - Invalid namespace.
- XSLT_
ERR_ INVALID_ SELECT - Invalid select expression.
- XSLT_
ERR_ INVALID_ TEST - Invalid test expression.
- XSLT_
ERR_ INVALID_ USE - Invalid use expression.
- XSLT_
ERR_ LEVEL_ ERROR - Error — processing may continue but results may be incomplete.
- XSLT_
ERR_ LEVEL_ FATAL - Fatal error — processing cannot continue.
- XSLT_
ERR_ LEVEL_ NONE - No error level (unset).
- XSLT_
ERR_ LEVEL_ WARNING - Warning — non-fatal issue.
- XSLT_
ERR_ MISSING_ ATTRIBUTE - Missing required attribute.
- XSLT_
ERR_ MISSING_ ELEMENT - Missing required element.
- XSLT_
ERR_ MISSING_ MATCH - Missing match attribute.
- XSLT_
ERR_ MISSING_ NAME - Missing name attribute.
- XSLT_
ERR_ MISSING_ NAMESPACE - Missing required namespace.
- XSLT_
ERR_ MISSING_ NS - Missing namespace.
- XSLT_
ERR_ MISSING_ SELECT - Missing select attribute.
- XSLT_
ERR_ MISSING_ TEST - Missing test attribute.
- XSLT_
ERR_ MISSING_ USE - Missing use attribute.
- XSLT_
ERR_ NONE - No error.
- XSLT_
ERR_ RECURSION - Recursion limit exceeded.
- XSLT_
ERR_ UNKNOWN - Unknown error.
Functions§
- xslt
Emit Message - Emit an
xsl:messagepayload through the transform error handler (or the globalxsltGenericErrorchannel), WITHOUT moving the transform context out of the OK state. - xslt
GetLast Error - Get the last XSLT error message as a NUL-terminated heap string.
- xslt
SetGeneric ⚠Debug Func - Global debug handler: the exported
xsltGenericDebugdata global incrate::abi::data_globals(upstreamxsltGenericDebug, a function pointer variable defaulting toxsltGenericDebugDefaultFunc— R-000174). - xslt
SetTransform Error Func - Set the transform error handler for a context.
- xslt
Transform Error - Report an XSLT error.
Type Aliases§
- xslt
Transform Error Func - Global XSLT error handler function type.