Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 7336546

Browse files
CompletionStages returned by CloudProviders no longer fail with IO and NIO exceptions but define their own exceptions with CloudProviderException being their common base.
Also, CloudProviderException no longer extends CompletionException due to strange behaviour of CompletableFuture which ditches intermediate causes when thrown ExecutionException: "In case of exceptional completion with a CompletionException, methods get() and get(long, TimeUnit) throw an ExecutionException with the same cause as held in the corresponding CompletionException."
1 parent 8472f23 commit 7336546

20 files changed

+167
-118
lines changed

src/main/java/org/cryptomator/cloudaccess/api/CloudProvider.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.cryptomator.cloudaccess.api;
22

3+
import org.cryptomator.cloudaccess.api.exceptions.CloudProviderException;
4+
35
import java.io.InputStream;
46
import java.nio.file.Path;
57
import java.util.Optional;
@@ -21,8 +23,8 @@ public interface CloudProvider {
2123
* <p>
2224
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
2325
* <ul>
24-
* <li>{@link java.nio.file.NoSuchFileException} If no item exists for the given path</li>
25-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
26+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If no item exists for the given path</li>
27+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
2628
* </ul>
2729
*
2830
* @param node The remote path of the file or folder, whose metadata to fetch.
@@ -37,10 +39,10 @@ public interface CloudProvider {
3739
* <p>
3840
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
3941
* <ul>
40-
* <li>{@link java.nio.file.NoSuchFileException} If no item exists for the given path</li>
41-
* <li>{@link java.nio.file.NotDirectoryException} If the path doesn't represent a folder</li>
42-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
43-
* <li>{@link InvalidPageTokenException} if <code>pageToekn</code> is invalid</li>
42+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If no item exists for the given path</li>
43+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.TypeMismatchException} If the path doesn't represent a folder</li>
44+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
45+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.InvalidPageTokenException} if <code>pageToken</code> is invalid</li>
4446
* </ul>
4547
*
4648
* @param folder The remote path of the folder to list.
@@ -90,8 +92,8 @@ default CompletionStage<InputStream> read(Path file, ProgressListener progressLi
9092
* <p>
9193
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
9294
* <ul>
93-
* <li>{@link java.nio.file.NoSuchFileException} If no item exists for the given path</li>
94-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
95+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If no item exists for the given path</li>
96+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
9597
* </ul>
9698
*
9799
* @param file A remote path referencing a file
@@ -107,9 +109,10 @@ default CompletionStage<InputStream> read(Path file, ProgressListener progressLi
107109
* <p>
108110
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
109111
* <ul>
110-
* <li>{@link java.nio.file.NoSuchFileException} If the parent directory of this file doesn't exist</li>
111-
* <li>{@link java.nio.file.FileAlreadyExistsException} If a node with the given path already exists and <code>replace</code> is false</li>
112-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
112+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If the parent directory of this file doesn't exist</li>
113+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.TypeMismatchException} If the path points to a node that isn't a file</li>
114+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.AlreadyExistsException} If a node with the given path already exists and <code>replace</code> is false</li>
115+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
113116
* </ul>
114117
*
115118
* @param file A remote path referencing a file
@@ -126,7 +129,7 @@ default CompletionStage<InputStream> read(Path file, ProgressListener progressLi
126129
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
127130
* <ul>
128131
* <li>{@link java.nio.file.FileAlreadyExistsException} If a node with the given path already exists</li>
129-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
132+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
130133
* </ul>
131134
*
132135
* @param folder The remote path of the folder to create.
@@ -139,8 +142,8 @@ default CompletionStage<InputStream> read(Path file, ProgressListener progressLi
139142
* <p>
140143
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
141144
* <ul>
142-
* <li>{@link java.nio.file.NoSuchFileException} If no item exists for the given path</li>
143-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
145+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If no item exists for the given path</li>
146+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
144147
* </ul>
145148
*
146149
* @param node The remote path of the file or folder to delete.
@@ -153,9 +156,9 @@ default CompletionStage<InputStream> read(Path file, ProgressListener progressLi
153156
* <p>
154157
* The returned CompletionStage might complete exceptionally with one of the following exceptions:
155158
* <ul>
156-
* <li>{@link java.nio.file.NoSuchFileException} If no item exists for the given source path</li>
157-
* <li>{@link java.nio.file.FileAlreadyExistsException} If a node with the given target path already exists and <code>replace</code> is false</li>
158-
* <li>{@link java.io.IOException} in case of generic I/O errors</li>
159+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.NotFoundException} If no item exists for the given source path</li>
160+
* <li>{@link org.cryptomator.cloudaccess.api.exceptions.AlreadyExistsException} If a node with the given target path already exists and <code>replace</code> is false</li>
161+
* <li>{@link CloudProviderException} in case of generic I/O errors</li>
159162
* </ul>
160163
*
161164
* @param source The remote path of the file or folder to be moved.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.cryptomator.cloudaccess.api.exceptions;
2+
3+
public class AlreadyExistsException extends CloudProviderException {
4+
5+
public AlreadyExistsException(Throwable cause) {
6+
super(cause);
7+
}
8+
9+
public AlreadyExistsException(String name) {
10+
super(name);
11+
}
12+
}

src/main/java/org/cryptomator/cloudaccess/api/exceptions/BackendException.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/org/cryptomator/cloudaccess/api/exceptions/CloudNodeAlreadyExistsException.java

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.cryptomator.cloudaccess.api.exceptions;
2+
3+
public class CloudProviderException extends RuntimeException {
4+
5+
public CloudProviderException() {
6+
super();
7+
}
8+
9+
public CloudProviderException(Throwable e) {
10+
super(e);
11+
}
12+
13+
public CloudProviderException(String message) {
14+
super(message);
15+
}
16+
17+
public CloudProviderException(String message, Throwable e) {
18+
super(message, e);
19+
}
20+
21+
}

src/main/java/org/cryptomator/cloudaccess/api/exceptions/ForbiddenException.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package org.cryptomator.cloudaccess.api.exceptions;
22

3-
public class InsufficientStorageException extends BackendException {
3+
public class InsufficientStorageException extends CloudProviderException {
44
}

src/main/java/org/cryptomator/cloudaccess/api/InvalidPageTokenException.java renamed to src/main/java/org/cryptomator/cloudaccess/api/exceptions/InvalidPageTokenException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package org.cryptomator.cloudaccess.api;
1+
package org.cryptomator.cloudaccess.api.exceptions;
22

3-
public class InvalidPageTokenException extends IllegalArgumentException {
3+
public class InvalidPageTokenException extends CloudProviderException {
44
public InvalidPageTokenException(String message) {
55
super(message);
66
}

src/main/java/org/cryptomator/cloudaccess/api/exceptions/NotFoundException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.cryptomator.cloudaccess.api.exceptions;
22

3-
public class NotFoundException extends BackendException {
3+
public class NotFoundException extends CloudProviderException {
44

55
public NotFoundException() {
66
}
77

8+
public NotFoundException(Throwable cause) {
9+
super(cause);
10+
}
11+
812
public NotFoundException(String name) {
913
super(name);
1014
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.cryptomator.cloudaccess.api.exceptions;
2+
3+
/**
4+
* Indicates that an operation expected a different {@link org.cryptomator.cloudaccess.api.CloudItemType}.
5+
*/
6+
public class TypeMismatchException extends CloudProviderException {
7+
8+
public TypeMismatchException() {
9+
}
10+
11+
public TypeMismatchException(Throwable cause) {
12+
super(cause);
13+
}
14+
15+
public TypeMismatchException(String name) {
16+
super(name);
17+
}
18+
}

0 commit comments

Comments
 (0)