forked from eXist-db/exist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] handle IllegalStateException in file:directory-list#2
fixes eXist-db#5028 The Java code of DirectoryList can throw an IllegalStateException when a non-existent directory is supplied as its first argument. This exception class is now handled in file:list#2. Additionally, the raised error now has a proper code `file:DIRECTORY_NOT_FOUND`. This will allow us in the future to add proper error codes to more errors raised by this module.
- Loading branch information
Showing
3 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
extensions/modules/file/src/main/java/org/exist/xquery/modules/file/FileErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.exist.xquery.modules.file; | ||
|
||
import org.exist.dom.QName; | ||
import org.exist.xquery.ErrorCodes; | ||
|
||
class FileErrorCode extends ErrorCodes.ErrorCode { | ||
public static final ErrorCodes.ErrorCode DIRECTORY_NOT_FOUND = new FileErrorCode("DIRECTORY_NOT_FOUND", "Index cannot be applied to the given expression."); | ||
|
||
FileErrorCode(String code, String description) { | ||
super(new QName(code, FileModule.NAMESPACE_URI, FileModule.PREFIX), description); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
extensions/modules/file/src/test/xquery/modules/file/directory-list.xqm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(: | ||
: eXist-db Open Source Native XML Database | ||
: Copyright (C) 2001 The eXist-db Authors | ||
: | ||
: [email protected] | ||
: http://www.exist-db.org | ||
: | ||
: This library is free software; you can redistribute it and/or | ||
: modify it under the terms of the GNU Lesser General Public | ||
: License as published by the Free Software Foundation; either | ||
: version 2.1 of the License, or (at your option) any later version. | ||
: | ||
: This library is distributed in the hope that it will be useful, | ||
: but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
: Lesser General Public License for more details. | ||
: | ||
: You should have received a copy of the GNU Lesser General Public | ||
: License along with this library; if not, write to the Free Software | ||
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
:) | ||
xquery version "3.1"; | ||
|
||
module namespace dirlist="http://exist-db.org/testsuite/modules/file/dirlist"; | ||
|
||
|
||
import module namespace file="http://exist-db.org/xquery/file"; | ||
import module namespace util="http://exist-db.org/xquery/util"; | ||
import module namespace helper="http://exist-db.org/xquery/test/util/helper" at "resource:util/helper.xqm"; | ||
|
||
declare namespace test="http://exist-db.org/xquery/xqsuite"; | ||
|
||
|
||
declare | ||
%test:assertError("file:DIRECTORY_NOT_FOUND") | ||
function dirlist:non-existent-error-code() { | ||
file:directory-list("/non/existent", ()) | ||
}; | ||
|
||
declare | ||
%test:assertXPath("contains($result,'basedir /non/existent does not exist.')") | ||
function dirlist:non-existent-error-description() { | ||
try { | ||
file:directory-list("/non/existent", ()) | ||
} catch file:DIRECTORY_NOT_FOUND { | ||
$err:description | ||
} | ||
}; |