eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
429 stars 179 forks source link

[BUG] some XPath exceptions are wrapped in generic exception, resulting in failing tests #4208

Open line-o opened 2 years ago

line-o commented 2 years ago

Describe the bug

XQTS and XQSuite tests expecting a specific XPath exception to be thrown may fail due to those exceptions being wrapped and re-thrown with an exception of another type.

In one instance err:XPTY0004 was wrapped in a generic org.exist.xquery.XPathException (in #4081)

https://github.com/eXist-db/exist/blob/2682f3b6e9a8275804640c4606a38d54eaef2d17/extensions/modules/file/src/test/xquery/modules/file/sync.xqm#L132-L144

Expected behavior

Exceptions to not be wrapped so that we can test for those errors.

To Reproduce

needs reproducible test, for now you can check out #4081 and modify the test annotation of sync:bad-options-5 to expect %test:assertError("err:XPTY0004")

Here is one example of such a failure in XQTS (there are many more):

<testcase classname="org.exist.xqts.runner.JUnitResultsSerializerActor$XQTSJUnitTest" name="UnaryLookup-018" time="0.0">
    <failure message="Expected: &apos;Error(XPST0003)&apos;, but query returned an error: QueryError(ERROR,exerr:ERROR org.exist.xquery.XPathException: err:XPST0003 unexpected token: 1.0 [at line 1, column 54]&#xa;)" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: Expected: &apos;Error(XPST0003)&apos;, but query returned an error: QueryError(ERROR,exerr:ERROR org.exist.xquery.XPathException: err:XPST0003 unexpected token: 1.0 [at line 1, column 54] [...]" 
    /></testcase>

I found a relatively trivial way to reproduce it

xquery version "3.1";

try {
    util:eval("(['a', 'b', 'c'], ['b', 'c', 'd'], ['e', 'f', 'b'])[?1.0 = 'a']")
}
catch err:XPST0003 {
    "got err:XPST0003"
}
catch * {
    "got " || $err:code
}

Context (please always complete the following information):

Additional context

line-o commented 5 months ago

I retested this issue today just out of curiosity.

exist version test with the above code
6.2.0 still affected
6.3.0-SNAPSHOT still affected
7.0.0-SNAPSHOT fixed