Skip to content

Align error codes with W3C XQuery spec#6263

Merged
line-o merged 3 commits into
eXist-db:developfrom
joewiz:bugfix/error-code-alignment
Apr 27, 2026
Merged

Align error codes with W3C XQuery spec#6263
line-o merged 3 commits into
eXist-db:developfrom
joewiz:bugfix/error-code-alignment

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Apr 25, 2026

Summary

Fixes several error code mismatches detected by XQTS misc-CombinedErrorCodes test set. Each fix changes only the error code constant used — no behavioral changes to error detection logic.

What Changed

XQDY0025 — Duplicate attribute detection in EnclosedExpr (~4 tests)

  • EnclosedExpr.java: When a DOMException with INUSE_ATTRIBUTE_ERR is caught during node copying in enclosed expressions, raise XQDY0025 instead of the generic exerr:ERROR. The duplicate attribute was already detected correctly — only the reported error code was wrong.

XQDY0074 — Invalid computed element/attribute names (~4 tests)

  • ElementConstructor.java: Computed element constructors now raise XQDY0074 (per XQuery 3.1 §3.9.3.1) instead of XPTY0004 when the name expression cannot be converted to a valid QName.
  • DynamicAttributeConstructor.java: Same fix for computed attribute constructors (§3.9.3.2).

FOCH0002 — Collation errors in fn: functions (~4 tests)

  • FunSort.java, FunIndexOf.java, FunContainsToken.java: These functions called context.getCollator(uri) which defaults to XQST0076 (a static error). Per F&O 3.1 §5.3.4, collation errors from function arguments should raise FOCH0002 (a dynamic error). The fix passes the correct error code, matching what CollatingFunction.getCollator() already does for other fn: functions.

Spec References

Test Plan

  • XQSuite tests pass (986 tests, 0 failures)
  • XPathQueryTest passes (148 tests, 0 failures)
  • XQTS misc-CombinedErrorCodes test set — verify ~12 additional tests pass after cherry-pick to next-v3

🤖 Generated with Claude Code

@joewiz joewiz requested a review from a team as a code owner April 25, 2026 21:50
@duncdrum
Copy link
Copy Markdown
Contributor

looks like a test needs to be adjusted

Error: core] [ERROR] Failures: 
Error: core] [ERROR]   XQueryContextTest.testReDeclareNamespaceEmptyPrefixFail:243 expected:<err:XQST00[33] Cannot bind prefix ...> but was:<err:XQST00[66] Cannot bind prefix ...>
[exist-core] [INFO] 
Error: core] [ERROR] Tests run: 6592, Failures: 1, Errors: 0, Skipped: 106

@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented Apr 27, 2026

[This response was co-authored with Claude Code. -Joe]

@duncdrum Thanks — you're right, the test assertion needs updating. The error code change from XQST0033 to XQST0066 is intentional (W3C alignment: XQST0066 is the correct code for rebinding the default namespace to a non-matching URI). Will update XQueryContextTest.testReDeclareNamespaceEmptyPrefixFail to expect XQST0066.

@line-o line-o requested a review from a team April 27, 2026 12:37
@line-o line-o added this to Wave 1 Apr 27, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Wave 1 Apr 27, 2026
@line-o line-o added the xquery issue is related to xquery implementation label Apr 27, 2026
@line-o line-o added this to the eXist-7.0.0 milestone Apr 27, 2026
@line-o
Copy link
Copy Markdown
Member

line-o commented Apr 27, 2026

@joewiz needs to be rebased

joewiz and others added 3 commits April 27, 2026 15:22
Fix several error code mismatches caught by XQTS misc-CombinedErrorCodes:

- XQDY0025: EnclosedExpr now detects INUSE_ATTRIBUTE_ERR DOMExceptions
  and raises XQDY0025 instead of generic exerr:ERROR (~4 tests)
- XQDY0074: Computed element/attribute constructors raise XQDY0074
  for invalid QNames instead of XPTY0004 (~4 tests)
- FOCH0002: fn:sort, fn:index-of, fn:contains-token now pass FOCH0002
  as the collation error code instead of defaulting to XQST0076 (~4 tests)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Continue error code alignment work for XQTS misc-CombinedErrorCodes:

- XQST0090: Character reference NumberFormatException now uses proper
  error code instead of generic exerr:ERROR (StringValue.java)
- XQST0067: Construction declaration duplicate check was using XQST0069
  (empty order) instead of XQST0067 (construction) (XQueryTree.g)
- XQST0069: Empty order declaration duplicate check was using XQST0065
  (ordering mode) instead of XQST0069 (empty order) (XQueryTree.g)
- XQST0066: Default element namespace rebinding now raises XQST0066
  instead of XQST0033 when prefix is empty (XQueryContext.java)
- XPTY0004: Variable type mismatch now includes proper error code
  instead of generic exerr:ERROR (VariableImpl.java)
- XPTY0019: toNodeSet() methods on sequence types now use XPTY0019
  instead of generic exerr:ERROR (ValueSequence, OrderedValueSequence,
  ArrayListValueSequence, RangeSequence)
- XQST0046: Invalid URI cast now uses XQST0046 instead of generic
  exerr:ERROR (AnyURIValue.java)
- XQST0009: Schema imports now properly rejected with XQST0009 instead
  of being silently ignored (XQueryTree.g)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… spec

testReDeclareNamespaceEmptyPrefixFail now expects err:XQST0066, matching
the W3C XQuery spec for default element namespace redeclaration. The empty
prefix branch in XQueryContext was aligned with the spec earlier in this
PR; updating the assertion to match.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joewiz joewiz force-pushed the bugfix/error-code-alignment branch from 3aa4662 to 623388a Compare April 27, 2026 19:22
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented Apr 27, 2026

[This response was co-authored with Claude Code. -Joe]

@line-o Rebased onto current develop (force-pushed). The conflict in ElementConstructor.java was from the copy-namespaces fix (#6222) — resolved by keeping the copy-namespaces save/restore block and applying our XQDY0074 error code change within it.

Copy link
Copy Markdown
Member

@line-o line-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@line-o line-o merged commit b7b6fd7 into eXist-db:develop Apr 27, 2026
9 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Wave 1 Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

xquery issue is related to xquery implementation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants