pyxsd.xslt.errors ================= .. py:module:: pyxsd.xslt.errors .. autoapi-nested-parse:: Errors raised by the advisory inspector and the normative XSLT front end. The advisory inspection error is an input/resource failure only. Normative errors carry the expanded XSLT or XPath error name, the phase that discovered the problem, the stylesheet module and package identity when known, the source location, any frame-derived dynamic stack, and the preserved underlying cause. Static errors use the exact code the specification assigns; a generic exception must never be substituted for one of them. Errors keep their own identity at XSLT boundaries. A parser, resource, XPath, or Python exception is wrapped only where the runtime has deliberately converted it into an XSLT dynamic error; its original object is retained as ``cause`` and ``__cause__``. Callback failures that were not deliberately converted are not catchable by a coded ``xsl:catch`` and are not eligible for implementation recovery. Attributes ---------- .. autoapisummary:: pyxsd.xslt.errors.ERROR_NAMESPACE pyxsd.xslt.errors.IMPLEMENTATION_BUDGET_CODE pyxsd.xslt.errors.UNSUPPORTED_FEATURE_CODE Exceptions ---------- .. autoapisummary:: pyxsd.xslt.errors.XsltInspectionError pyxsd.xslt.errors.XsltError pyxsd.xslt.errors.XsltStaticError pyxsd.xslt.errors.XsltDynamicError pyxsd.xslt.errors.XsltCircularityError pyxsd.xslt.errors.XsltSerializationError Functions --------- .. autoapisummary:: pyxsd.xslt.errors.normalized_error_code pyxsd.xslt.errors.is_static_error_code pyxsd.xslt.errors.expanded_error_code pyxsd.xslt.errors.error_code_from_exception pyxsd.xslt.errors.is_budget_alarm Module Contents --------------- .. py:data:: ERROR_NAMESPACE :value: 'http://www.w3.org/2005/xqt-errors' .. py:data:: IMPLEMENTATION_BUDGET_CODE :value: 'PYXSD-XSLT-001' .. py:data:: UNSUPPORTED_FEATURE_CODE :value: 'PYXSD-XSLT-002' .. py:function:: normalized_error_code(code) Return the local part of one error code without assuming a namespace. .. py:function:: is_static_error_code(code) Whether *code* identifies a static XPath or XSLT error. ``XPST``/``XQST`` are static XPath/XQuery errors and ``XTSE`` is the XSLT static-error family. XSLT 3.0 section 8.3 says static errors are never caught, so these codes stay outside ``xsl:try`` even if a processor reports them while executing an expression. .. py:function:: expanded_error_code(code) Return one error code as an expanded QName when its namespace is known. A bare local code belongs to the standard error namespace. A prefixed code with an unknown prefix cannot be expanded without a static context, so it is returned unchanged rather than guessed. .. py:function:: error_code_from_exception(error: BaseException, default: None = None) -> str | None error_code_from_exception(error: BaseException, default: str) -> str Extract a specification error code from an exception without rewriting it. Standard error-namespace codes are returned in their familiar local form. A custom QName is preserved as an expanded name so an extension error in a non-standard namespace can still match a coded ``xsl:catch``. *default* supplies the fallback used by callers whose boundary maps an unidentifiable failure to a specific error code. .. py:exception:: XsltInspectionError Advisory stylesheet inspection could not read or bind its inputs. This is an input/resource failure, not an XSLT static error. Schema legality findings and instance binding findings are reported on :class:`~pyxsd.xslt.inspection.StylesheetInspection.report` instead. .. py:exception:: XsltError(message, *, code = None, phase = None, uri = None, module = None, package = None, location = None, stack = (), cause = None, description = None, has_description = True, value = (), line_number = None, column_number = None) Base class for normative XSLT compilation and execution errors. ``code`` is an XSLT (``XTSE``/``XTTE``/``XTDE``) or XPath (``XPST``/ ``XPTY``) error code, stored as supplied. ``phase`` names the processing phase, ``uri``/``module`` the relevant stylesheet or resource, ``package`` the containing package, and ``location`` one source occurrence. ``stack`` is derived from explicit execution frames, never from the Python call stack. ``cause`` preserves a parser, resource, expression, or callback exception instead of replacing its identity with this error. ``description``, ``value``, ``line_number``, and ``column_number`` carry the standard ``err:*`` catch metadata. ``has_description`` distinguishes an explicitly absent description (``fn:error`` with one argument) from an empty one. Line and column numbers remain ``None`` when the source occurrence does not carry them. .. py:attribute:: code :value: None .. py:attribute:: phase :value: None .. py:attribute:: uri :value: None .. py:attribute:: module :value: None .. py:attribute:: package :value: None .. py:attribute:: location :value: None .. py:attribute:: stack :type: tuple[pyxsd.xslt.runtime.frames.FrameDiagnostic, ...] :value: () .. py:attribute:: cause :value: None .. py:attribute:: description .. py:attribute:: has_description :value: True .. py:attribute:: value :type: tuple[pyxsd.xdm.XdmItem, ...] :value: () .. py:attribute:: messages :type: tuple[pyxsd.xslt.results.Message, ...] :value: () .. py:attribute:: warnings :type: tuple[str, ...] :value: () .. py:attribute:: line_number :value: None .. py:attribute:: column_number :value: None .. py:property:: expanded_code :type: str | None The error code as an expanded QName, when its namespace is known. .. py:property:: catchable :type: bool Whether a coded ``xsl:catch`` may consume this error. Only dynamically signaled XSLT/XPath errors are catchable. Static and serialization errors are outside ``xsl:try``, and a foreign callback failure is not converted merely because it crossed an XSLT boundary. .. py:method:: matches_catch(errors = None, *, namespaces = None) Whether one ``xsl:catch/@errors`` list selects this error. .. py:method:: attach_diagnostics(stack, *, module = None, package = None) Attach frame-derived context only where it is not already known. .. py:method:: attach_messages(messages, warnings) Retain messages and warnings emitted before this failure. A failed transformation never returns a result, so its diagnostics would otherwise be lost at the host boundary. Messages already attached by an inner invocation stay first; the outer invocation's own messages follow. .. py:exception:: XsltStaticError(message, *, code = None, phase = 'static', uri = None, module = None, package = None, location = None, stack = (), cause = None, description = None, has_description = True, value = (), line_number = None, column_number = None) A static error, reported before any transformation output starts. A static-expression failure keeps its original XPath code; a stylesheet resource or structural failure uses the exact ``XTSE`` code for that rule. .. py:exception:: XsltDynamicError(message, *, code = None, phase = 'dynamic', uri = None, module = None, package = None, location = None, stack = (), cause = None, allow_catch = True, description = None, has_description = True, value = (), line_number = None, column_number = None) A dynamic error raised while executing a transformation. ``code`` is normally an XSLT ``XTDE``/``XTTE`` code or an XPath error code. The execution runtime's own resource limits use the stable implementation code ``PYXSD-XSLT-001``; callers can test it exactly without depending on message text. ``allow_catch`` is false for foreign callback failures that crossed an XSLT boundary without being deliberately converted. .. py:attribute:: allow_catch :value: True .. py:property:: catchable :type: bool Whether a coded ``xsl:catch`` may consume this error. Only dynamically signaled XSLT/XPath errors are catchable. Static and serialization errors are outside ``xsl:try``, and a foreign callback failure is not converted merely because it crossed an XSLT boundary. .. py:exception:: XsltCircularityError(message, **kwargs) An engine-detected circularity, reported as ``XTDE0640``. XSLT 3.0 section 5.5.4 makes a dynamic error during pattern evaluation a non-match, but requires a circularity to be reported even there. This marker distinguishes the engine's own circularity from an unrelated dynamic error that happens to carry the same code (for example a forged ``xsl:message`` code), which the masking rule still covers. .. py:exception:: XsltSerializationError(message, *, code = None, phase = 'serialization', uri = None, module = None, package = None, location = None, stack = (), cause = None, secondary = False, description = None, has_description = True, value = (), line_number = None, column_number = None) A serialization error, distinct from the transformation's dynamic phase. A serialization error while writing a secondary result is treated as a dynamic error of the ``xsl:result-document`` instruction and may be caught; a principal-result serialization error happens after the transformation and cannot be caught. ``secondary`` records which boundary raised it. .. py:attribute:: secondary :value: False .. py:property:: catchable :type: bool Whether a coded ``xsl:catch`` may consume this error. Only dynamically signaled XSLT/XPath errors are catchable. Static and serialization errors are outside ``xsl:try``, and a foreign callback failure is not converted merely because it crossed an XSLT boundary. .. py:function:: is_budget_alarm(error) Whether *error* is an execution-budget alarm rather than an engine failure. Two independent budgets can expire while the engine works, and neither one describes a failure of the stylesheet or of the expression being evaluated: * the caller's wall-clock alarm, which the conformance harness raises as a ``TimeoutError`` from ``SIGALRM``; and * the engine's own ``ExecutionLimits`` budget, which arrives as a dynamic error carrying :data:`IMPLEMENTATION_BUDGET_CODE`. A handler that converts a caught exception into a non-match or a different error must let both through unchanged. Converting the alarm cancels the bound the caller placed on the work, so the runaway expression keeps running instead of stopping at its budget. ``TimeoutError`` is class-only: ``socket.timeout``, ``asyncio.TimeoutError`` and ``concurrent.futures.TimeoutError`` are that class on Python 3.11+, so a foreign timeout arriving at a guarded engine site is treated as an alarm. Extension and Python-rule callbacks are converted at their own boundary before this predicate ever sees the error.