-
-
Notifications
You must be signed in to change notification settings - Fork 179
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 #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
87 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
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
/* | ||
* 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 | ||
*/ | ||
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", "The directory could not be found."); | ||
|
||
FileErrorCode(String code, String description) { | ||
super(new QName(code, FileModule.NAMESPACE_URI, FileModule.PREFIX), description); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
(: | ||
: 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"; | ||
|
||
|
||
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.') or 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 | ||
} | ||
}; |