Skip to content

Commit 2a93804

Browse files
committed
Improve chunk error handling further
1 parent 78e160e commit 2a93804

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

core/src/main/java/de/bluecolored/bluemap/core/world/ChunkConsumer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
*/
2525
package de.bluecolored.bluemap.core.world;
2626

27+
import de.bluecolored.bluemap.core.logger.Logger;
28+
29+
import java.io.IOException;
30+
2731
@FunctionalInterface
2832
public interface ChunkConsumer<T> {
2933

@@ -33,6 +37,10 @@ default boolean filter(int chunkX, int chunkZ, int lastModified) {
3337

3438
void accept(int chunkX, int chunkZ, T chunk);
3539

40+
default void fail(int chunkX, int chunkZ, IOException exception) throws IOException {
41+
throw exception;
42+
}
43+
3644
@FunctionalInterface
3745
interface ListOnly<T> extends ChunkConsumer<T> {
3846

core/src/main/java/de/bluecolored/bluemap/core/world/Region.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public boolean filter(int x, int z, int lastModified) {
4545
public void accept(int chunkX, int chunkZ, T chunk) {
4646
this.foundChunk = chunk;
4747
}
48+
4849
}
4950

5051
SingleChunkConsumer singleChunkConsumer = new SingleChunkConsumer();

core/src/main/java/de/bluecolored/bluemap/core/world/mca/ChunkGrid.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,14 @@ public void accept(int chunkX, int chunkZ, T chunk) {
111111
Vector2i chunkPos = VECTOR_2_I_CACHE.get(chunkX, chunkZ);
112112
chunkCache.put(chunkPos, chunk);
113113
}
114+
115+
@Override
116+
public void fail(int chunkX, int chunkZ, IOException ex) {
117+
Logger.global.logDebug("Failed to preload chunk (%d, %d) from region ('%s' -> x:%d, z:%d): %s".formatted(chunkX, chunkZ, regionFolder, x, z, ex));
118+
}
114119
});
115120
} catch (IOException ex) {
116-
Logger.global.logDebug("Unexpected exception trying to load preload region ('%s' -> x:%d, z:%d): %s".formatted(regionFolder, x, z, ex));
121+
Logger.global.logDebug("Unexpected exception trying to preload region ('%s' -> x:%d, z:%d): %s".formatted(regionFolder, x, z, ex));
117122
}
118123
}
119124

core/src/main/java/de/bluecolored/bluemap/core/world/mca/region/LinearRegion.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,15 @@ public void iterateAllChunks(ChunkConsumer<T> consumer) throws IOException {
170170
chunkDataBuffer = new byte[length];
171171
dIn.readFully(chunkDataBuffer, 0, length);
172172

173-
T chunk = chunkLoader.load(chunkDataBuffer, 0, length, Compression.NONE);
174-
consumer.accept(chunkX, chunkZ, chunk);
173+
try {
174+
T chunk = chunkLoader.load(chunkDataBuffer, 0, length, Compression.NONE);
175+
consumer.accept(chunkX, chunkZ, chunk);
176+
} catch (IOException ex) {
177+
consumer.fail(chunkX, chunkZ, ex);
178+
} catch (Exception ex) {
179+
consumer.fail(chunkX, chunkZ, new IOException(ex));
180+
}
181+
175182
} else {
176183
// skip before reading the next chunk, but only if there is a next chunk
177184
// that we actually want to read, to avoid decompressing unnecessary data

core/src/main/java/de/bluecolored/bluemap/core/world/mca/region/MCARegion.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,15 @@ public void iterateAllChunks(ChunkConsumer<T> consumer) throws IOException {
152152
channel.position(offset);
153153
readFully(channel, chunkDataBuffer, 0, size);
154154

155-
T chunk = loadChunk(chunkDataBuffer, size);
156-
consumer.accept(chunkX, chunkZ, chunk);
155+
try {
156+
T chunk = loadChunk(chunkDataBuffer, size);
157+
consumer.accept(chunkX, chunkZ, chunk);
158+
} catch (IOException ex) {
159+
consumer.fail(chunkX, chunkZ, ex);
160+
} catch (Exception ex) {
161+
consumer.fail(chunkX, chunkZ, new IOException(ex));
162+
}
163+
157164
}
158165
}
159166
}

0 commit comments

Comments
 (0)