try-catch-001

Tests that catch can receive multiple documents.

Test is expected to pass.

The pipeline

<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:err="http://www.w3.org/ns/xproc-error" xmlns:ex="http://example.com/ns/step"
                xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:output port="result"/>
   
   <p:try>
      <p:error name="my-error" code="ex:first-code">
         <p:with-input port="source">
            <p:inline>
               <doc1/>
            </p:inline>
            <p:inline>
               <doc2/>
            </p:inline>
            <p:inline>
               <doc3/>
            </p:inline>
         </p:with-input>
      </p:error>
      <p:catch name="catch">
         <p:identity>
            <p:with-input pipe="error@catch"/>
         </p:identity>
      </p:catch>
   </p:try>
</p:declare-step>

Result

<c:errors xmlns:c="http://www.w3.org/ns/xproc-step"
          xmlns:cx="http://xmlcalabash.com/ns/extensions" xmlns:ex="http://example.com/ns/step"
          xmlns:fnerr="http://www.w3.org/2005/xqt-errors" xmlns:p="http://www.w3.org/ns/xproc"
          xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <c:error name="my-error" type="p:error"
            code="ex:first-code"
            href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/tests/try-catch-001.xml" line="30" column="55">
      <cx:input-location href="file:/woodpecker/src/codeberg.org/xmlcalabash/xmlcalabash3/tests/extra-suite/test-suite/tests/try-catch-001.xml"/>
      <cx:message>(no message for error)</cx:message>
      <doc1 xmlns:err="http://www.w3.org/ns/xproc-error"/>
      <doc2 xmlns:err="http://www.w3.org/ns/xproc-error"/>
      <doc3 xmlns:err="http://www.w3.org/ns/xproc-error"/>
      <cx:stack-trace>
         <cx:stack-frame type="p:error" name="my-error"/>
      </cx:stack-trace>
   </c:error>
</c:errors>

Schematron checks

<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron"
          xmlns:t="http://xproc.org/ns/testsuite/3.0" queryBinding="xslt2">
   <s:ns prefix="c"
         uri="http://www.w3.org/ns/xproc-step"/>
   <s:ns prefix="cx"
         uri="http://xmlcalabash.com/ns/extensions"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="c:errors">The document is wrong</s:assert>
      </s:rule>
   </s:pattern>
   <s:pattern>
      <s:rule context="/c:errors">
         <s:assert test="count(c:error) = 1">Wrong number of errors</s:assert>
         <s:assert test="c:error/@name = 'my-error'">Wrong error</s:assert>
         <s:assert test="count(c:error/* except c:error/cx:*) = 3">Wrong number of documents</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

23 Jan 2026, Norm Tovey-Walsh
Created test.