Skip to content

Commit c645867

Browse files
committed
[bugfix] Correct some XPath/XQuery error messages
1 parent 3c82292 commit c645867

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@
11191119
<include>src/main/java/org/exist/xquery/Module.java</include>
11201120
<include>src/main/java/org/exist/xquery/NamedFunctionReference.java</include>
11211121
<include>src/main/java/org/exist/xquery/Optimizer.java</include>
1122+
<include>src/main/java/org/exist/xquery/Option.java</include>
11221123
<include>src/main/java/org/exist/xquery/PerformanceStatsImpl.java</include>
11231124
<include>src/test/java/org/exist/xquery/RestBinariesTest.java</include>
11241125
<include>src/test/java/org/exist/xquery/StoredModuleTest.java</include>
@@ -1169,6 +1170,7 @@
11691170
<include>src/main/java/org/exist/xquery/functions/fn/FunDefaultCollation.java</include>
11701171
<include>src/main/java/org/exist/xquery/functions/fn/FunDistinctValues.java</include>
11711172
<include>src/main/java/org/exist/xquery/functions/fn/FunDoc.java</include>
1173+
<include>src/main/java/org/exist/xquery/functions/fn/FunElementWithId.java</include>
11721174
<include>src/main/java/org/exist/xquery/functions/fn/FunEmpty.java</include>
11731175
<include>src/main/java/org/exist/xquery/functions/fn/FunEncodeForURI.java</include>
11741176
<include>src/main/java/org/exist/xquery/functions/fn/FunEndsWith.java</include>
@@ -1781,6 +1783,7 @@
17811783
<exclude>src/main/java/org/exist/xquery/NamedFunctionReference.java</exclude>
17821784
<exclude>src/main/java/org/exist/xquery/NameTest.java</exclude>
17831785
<exclude>src/main/java/org/exist/xquery/Optimizer.java</exclude>
1786+
<exclude>src/main/java/org/exist/xquery/Option.java</exclude>
17841787
<exclude>src/main/java/org/exist/xquery/PerformanceStatsImpl.java</exclude>
17851788
<exclude>src/test/java/org/exist/xquery/RestBinariesTest.java</exclude>
17861789
<exclude>src/test/java/org/exist/xquery/StoredModuleTest.java</exclude>
@@ -1835,6 +1838,7 @@
18351838
<exclude>src/main/java/org/exist/xquery/functions/fn/FunDistinctValues.java</exclude>
18361839
<exclude>src/main/java/org/exist/xquery/functions/fn/FunDoc.java</exclude>
18371840
<exclude>src/main/java/org/exist/xquery/functions/fn/FunDocAvailable.java</exclude>
1841+
<exclude>src/main/java/org/exist/xquery/functions/fn/FunElementWithId.java</exclude>
18381842
<exclude>src/main/java/org/exist/xquery/functions/fn/FunEmpty.java</exclude>
18391843
<exclude>src/main/java/org/exist/xquery/functions/fn/FunEncodeForURI.java</exclude>
18401844
<exclude>src/main/java/org/exist/xquery/functions/fn/FunEndsWith.java</exclude>

exist-core/src/main/java/org/exist/xquery/Option.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -60,8 +84,9 @@ public Option(QName qname, String contents) throws XPathException {
6084
}
6185

6286
public Option(final Expression expression, QName qname, String contents) throws XPathException {
63-
if (qname.getPrefix() == null || qname.getPrefix().isEmpty())
64-
{throw new XPathException(expression, "XPST0081: options must have a prefix");}
87+
if (qname.getPrefix() == null || qname.getPrefix().isEmpty()) {
88+
throw new XPathException(expression, ErrorCodes.W3CErrorCode.XPST0081, "Options must have a prefix");
89+
}
6590
this.qname = qname;
6691
this.contents = contents;
6792
}

exist-core/src/main/java/org/exist/xquery/XQueryContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,15 +1993,15 @@ public Variable declareVariable(final QName qname, final boolean external, final
19931993
//Type.EMPTY is *not* a subtype of other types ; checking cardinality first
19941994
if (!var.getSequenceType().getCardinality().isSuperCardinalityOrEqualOf(actualCardinality)) {
19951995
throw new XPathException(rootExpression, ErrorCodes.XPTY0004,
1996-
"XPTY0004: Invalid cardinality for variable $" + var.getQName() + ". " +
1996+
"Invalid cardinality for variable $" + var.getQName() + ". " +
19971997
"Expected " + var.getSequenceType().getCardinality().getHumanDescription() + ", " +
19981998
"got " + actualCardinality.getHumanDescription());
19991999
}
20002000

20012001
//TODO : ignore nodes right now ; they are returned as xs:untypedAtomicType
20022002
if (!val.isEmpty() && !Type.subTypeOf(val.getItemType(), var.getSequenceType().getPrimaryType())) {
20032003
throw new XPathException(rootExpression, ErrorCodes.XPTY0004,
2004-
"XPTY0004: Invalid type for variable $" + var.getQName() + ". " +
2004+
"Invalid type for variable $" + var.getQName() + ". " +
20052005
"Expected " + Type.getTypeName(var.getSequenceType().getPrimaryType()) + ", " +
20062006
"got " + Type.getTypeName(val.getItemType()));
20072007
}

exist-core/src/main/java/org/exist/xquery/functions/fn/FunElementWithId.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -78,9 +102,9 @@ public Sequence eval(final Sequence[] args, Sequence contextSequence) throws XPa
78102
if (getArgumentCount() == 2) {
79103
final Sequence nodes = getArgument(1).eval(contextSequence, null);
80104
if (nodes.isEmpty()) {
81-
throw new XPathException(this, ErrorCodes.XPDY0002, "XPDY0002: no node or context item for fn:id", nodes);
105+
throw new XPathException(this, ErrorCodes.XPDY0002, "No node or context item for fn:id", nodes);
82106
} else if (!Type.subTypeOf(nodes.itemAt(0).getType(), Type.NODE)) {
83-
throw new XPathException(this, ErrorCodes.XPTY0004, "XPTY0004: fn:id() argument is not a node", nodes);
107+
throw new XPathException(this, ErrorCodes.XPTY0004, "fn:id() argument is not a node", nodes);
84108
}
85109
NodeValue node = (NodeValue)nodes.itemAt(0);
86110
if (node.getImplementationType() == NodeValue.IN_MEMORY_NODE) {

exist-core/src/main/java/org/exist/xquery/functions/fn/FunId.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
131131
final Sequence nodes = getArgument(1).eval(contextSequence, null);
132132
if (nodes.isEmpty()) {
133133
logger.error("{} No node or context item for fn:id", ErrorCodes.XPDY0002);
134-
throw new XPathException(this, ErrorCodes.XPDY0002, "XPDY0002: no node or context item for fn:id", nodes);
134+
throw new XPathException(this, ErrorCodes.XPDY0002, "No node or context item for fn:id", nodes);
135135
}
136136
if (!Type.subTypeOf(nodes.itemAt(0).getType(), Type.NODE)) {
137137
logger.error("{} fn:id() argument is not a node", ErrorCodes.XPTY0004);
138-
throw new XPathException(this, ErrorCodes.XPTY0004, "XPTY0004: fn:id() argument is not a node", nodes);
138+
throw new XPathException(this, ErrorCodes.XPTY0004, "fn:id() argument is not a node", nodes);
139139
}
140140
NodeValue node = (NodeValue)nodes.itemAt(0);
141141
if (node.getImplementationType() == NodeValue.IN_MEMORY_NODE)

0 commit comments

Comments
 (0)