Project

Profile

Help

Empty err:code

Added by Vladimir Nesterovsky almost 6 years ago

While doing some transformation we got an exception. That's ok. But what we did not like is that err:code was empty.

Here is an example.

<xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:err="http://www.w3.org/2005/xqt-errors">

  <xsl:template match="/">
    <xsl:try>
      <xsl:variable name="uri" as="xs:anyURI" select="
        resolve-uri('notice trailing space /out.xml')"/>
    
      <xsl:message select="$uri"/>
    
      <xsl:result-document href="{$uri}">
        <out/>
      </xsl:result-document>

      <xsl:catch>
        <xsl:message select="'$err:code: ' || $err:code  || ', $err:description: ' || $err:description"/>
      </xsl:catch>
    </xsl:try>
  </xsl:template>

</xsl:stylesheet>

Output is:

file:/C:/.../notice trailing space /out.xml $err:code: , $err:description: Failed to create output file file:/C:/.../notice%20trailing%20space%20/out.xml(The system cannot find the path specified)


Replies (8)

Please register to reply

RE: Empty err:code - Added by Vladimir Nesterovsky almost 6 years ago

This message was not answered. I suspect it's just slipped out.

My concern is that, I think, err:code should never be empty sequence within xsl:catch handler, which I see in the example.

Note: I run on Windows.

RE: Empty err:code - Added by O'Neil Delpratt almost 6 years ago

Hi,

What Saxon version are you running?

In Saxon 9.9 the error code I get is FORG0002.

RE: Empty err:code - Added by Michael Kay almost 6 years ago

I think there will always be some cases where an exception occurs without an error code being assigned, and although we may have fixed this particular case we should probably have a general strategy. I think that if try/catch catches an exception that has somehow been generated with no specific error code, we should probably bind $err:code to some "catch-all" code such as err:XXXX9999.

However, individual cases where there is no error code should be fixed as we find them.

RE: Empty err:code - Added by Vladimir Nesterovsky almost 6 years ago

I've just retested it and see empty err:code

Windows 10, jdk 1.8.0_172, Saxon-HE/9.9.0-2 from maven.

RE: Empty err:code - Added by O'Neil Delpratt almost 6 years ago

Please try Saxon-HE/9.9.1-1 on maven

RE: Empty err:code - Added by Vladimir Nesterovsky almost 6 years ago

Please try Saxon-HE/9.9.1-1 on maven

Exactly same outcome.

I even started it in debugger and reached to TryCatch.java, line 330.

        } catch (XPathException err) {
            if (err.isGlobalError()) {
                err.setIsGlobalError(false);
            } else {
                StructuredQName code = err.getErrorCodeQName();

code is null.

containedException is: java.io.IOException: The system cannot find the path specified

RE: Empty err:code - Added by O'Neil Delpratt almost 6 years ago

I am using a macOS machine. It is possible we are seeing differences between platforms. I will try a windows machine.

RE: Empty err:code - Added by Michael Kay almost 6 years ago

Note that on the streaming path (TryCatchAdjunct) try/catch substitutes code Saxon:XXXX9999 if an error with no specific error code is caught. TryCatch.evaluateItem instead substitutes Saxon:SXWN9000. The iterate() and process() methods make no substitution. I propose to use Saxon;XXXX9999 in all four cases.

    (1-8/8)

    Please register to reply