Skip to content

Commit 7abb96e

Browse files
committed
MapillaryImageUtils: Handle cancellation or other errors better
Signed-off-by: Taylor Smock <tsmock@meta.com>
1 parent 17144c0 commit 7abb96e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryImageUtils.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// License: GPL. For details, see LICENSE file.
22
package org.openstreetmap.josm.plugins.mapillary.utils;
33

4+
import java.io.IOException;
45
import java.time.Instant;
56
import java.util.Locale;
7+
import java.util.concurrent.CancellationException;
68
import java.util.concurrent.CompletableFuture;
79
import java.util.function.Predicate;
810
import java.util.regex.Matcher;
@@ -13,6 +15,7 @@
1315

1416
import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
1517
import org.openstreetmap.josm.data.cache.CacheEntry;
18+
import org.openstreetmap.josm.data.cache.ICachedLoaderListener;
1619
import org.openstreetmap.josm.data.osm.INode;
1720
import org.openstreetmap.josm.data.osm.IPrimitive;
1821
import org.openstreetmap.josm.data.osm.IWay;
@@ -136,8 +139,17 @@ public static CompletableFuture<BufferedImageCacheEntry> getImage(@Nonnull INode
136139
}
137140
if (MapillaryImageUtils.isDownloadable(image)) {
138141
CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
139-
CacheUtils.submit(image, type,
140-
(entry, attributes, result) -> cacheImageFuture(image, completableFuture, entry));
142+
CacheUtils.submit(image, type, (entry, attributes, result) -> {
143+
if (result == ICachedLoaderListener.LoadResult.SUCCESS) {
144+
cacheImageFuture(image, completableFuture, entry);
145+
} else if (result == ICachedLoaderListener.LoadResult.CANCELED) {
146+
completableFuture.completeExceptionally(new CancellationException(
147+
"Mapillary Image download was cancelled: " + MapillaryImageUtils.getKey(image)));
148+
} else {
149+
completableFuture.completeExceptionally(new IOException(
150+
"Mapillary Image could not be downloaded: " + MapillaryImageUtils.getKey(image)));
151+
}
152+
});
141153
return completableFuture;
142154
} else if (getKey(image) > 0) {
143155
CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();

0 commit comments

Comments
 (0)