Report silent pregen failures instead of swallowing them

Empty catch (Throwable ignored) blocks in pregen hid failed capability probes, a stranded plugin chunk ticket and failed mantle cleanup. Probes now log their name and cause at debug through PregenDiagnostics, and real losses go through IrisLogging.reportError. The chunk load failure trace is emitted before the metrics snapshot so a failing snapshot cannot silence it.

Upstream: e030ac3be
This commit is contained in:
piexel committed 2026-11-10 01:29:00 +01:00
1 parent ae60b14402
commit 19129c2eb8
6 files changed
+290 -12

No files matched your search

@@ -0,0 +1,43 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.pregenerator;
import art.arcane.iris.spi.IrisLogging;
public final class PregenDiagnostics {
private PregenDiagnostics() {
}
public static void probeFailed(String probe, Throwable failure) {
IrisLogging.debug("Pregen probe " + describeProbe(probe) + " failed: " + describeFailure(failure));
}
public static String describeProbe(String probe) {
return probe == null || probe.isBlank() ? "unnamed" : probe;
}
public static String describeFailure(Throwable failure) {
if (failure == null) {
return "no throwable reported";
}
String message = failure.getMessage();
return message == null ? failure.getClass().getName() : failure.getClass().getName() + ": " + message;
}
}
@@ -170,7 +170,8 @@ public final class PregenMantleBackpressure {
try {
return cancelled.getAsBoolean();
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("pregen cancellation state", e);
return false;
}
}
@@ -178,7 +179,8 @@ public final class PregenMantleBackpressure {
private Mantle resolveMantle() {
try {
return mantleSupplier.get();
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("mantle handle for backpressure", e);
return null;
}
}
@@ -22,6 +22,7 @@ import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.core.IrisPaperLikeBackendMode;
import art.arcane.iris.core.IrisRuntimeSchedulerMode;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.pregenerator.PregenDiagnostics;
import art.arcane.iris.core.pregenerator.PregenListener;
import art.arcane.iris.core.pregenerator.PregenMantleBackpressure;
import art.arcane.iris.core.pregenerator.PregeneratorMethod;
@@ -214,7 +215,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
if (coreThreads instanceof Thread[] threadsArray) {
return threadsArray.length;
}
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("moonrise worker pool size", e);
}
return -1;
@@ -240,7 +242,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
int resolved = radius > 0 ? Math.max(1, (int) Math.ceil(radius / 32.0)) : 2;
evictionWindowRegions = resolved;
return resolved;
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("mantle radius for eviction window", e);
return 2;
}
}
@@ -409,7 +412,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
private void unloadChunkSafely(int cx, int cz) {
try {
world.removePluginChunkTicket(cx, cz, BukkitPlatform.plugin());
} catch (Throwable ignored) {
} catch (Throwable e) {
IrisLogging.reportError("Async pregen could not release the plugin chunk ticket at " + cx + "," + cz
+ " in world " + world.getName() + "; the chunk stays pinned in memory.", e);
}
try {
@@ -490,11 +495,12 @@ public class AsyncPregenMethod implements PregeneratorMethod {
}
private Chunk onChunkFutureFailure(int x, int z, Throwable throwable) {
try {
IrisLogging.warn("Failed async pregen chunk load at " + x + "," + z + ". " + metricsSnapshot());
IrisLogging.reportError("Failed async pregen chunk load at " + x + "," + z + ".", throwable);
IrisLogging.reportError(throwable);
try {
IrisLogging.warn("Async pregen state at the failed chunk " + x + "," + z + ". " + metricsSnapshot());
} catch (Throwable e) {
PregenDiagnostics.probeFailed("pregen metrics snapshot", e);
}
return null;
@@ -780,7 +786,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
if (engine != null) {
try {
engine.getMantle().forceCleanupChunk(x, z);
} catch (Throwable ignored) {
} catch (Throwable e) {
IrisLogging.reportError("Async pregen mantle cleanup failed at chunk " + x + "," + z
+ " in world " + world.getName() + "; tectonic plates for that chunk stay resident.", e);
}
}
}
@@ -801,7 +809,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
metricsEngine = resolvedEngine;
}
return resolvedEngine;
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("engine access for world " + world.getName(), e);
return null;
}
}
@@ -1154,7 +1163,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
requestMonitoredChunkAsync(x, z)
.whenComplete((chunk, throwable) -> completeChunk(x, z, listener, chunk, throwable));
return;
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("folia direct chunk request at " + x + "," + z
+ ", falling back to a region task", e);
}
Runnable regionTask = () -> {
@@ -19,6 +19,7 @@
package art.arcane.iris.core.pregenerator.methods;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.pregenerator.PregenDiagnostics;
import art.arcane.iris.core.pregenerator.PregenListener;
import art.arcane.iris.core.pregenerator.PregeneratorMethod;
import art.arcane.iris.core.tools.IrisToolbelt;
@@ -101,7 +102,8 @@ public class MedievalPregenMethod implements PregeneratorMethod {
if (cached != null) {
cachedEngine = cached;
}
} catch (Throwable ignored) {
} catch (Throwable e) {
PregenDiagnostics.probeFailed("engine access for world " + world.getName(), e);
}
return cached;
}
@@ -0,0 +1,84 @@
package art.arcane.iris.core.pregenerator;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.LogLevel;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
public class PregenDiagnosticsTest {
private final List<String> emitted = new ArrayList<>();
private final List<LogLevel> levels = new ArrayList<>();
private IrisPlatform previousPlatform;
@Before
public void captureLog() {
previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
IrisPlatforms.unbind();
emitted.clear();
levels.clear();
IrisPlatform platform = mock(IrisPlatform.class);
doAnswer(invocation -> {
levels.add(invocation.getArgument(0, LogLevel.class));
emitted.add(invocation.getArgument(1, String.class));
return null;
}).when(platform).log(ArgumentMatchers.any(LogLevel.class), ArgumentMatchers.anyString());
IrisPlatforms.bind(platform);
}
@After
public void restorePlatform() {
IrisPlatforms.unbind();
if (previousPlatform != null) {
IrisPlatforms.bind(previousPlatform);
}
}
@Test
public void aFailedProbeReportsItsNameClassAndMessageAtDebug() {
PregenDiagnostics.probeFailed("moonrise worker pool size", new IllegalStateException("no such field"));
assertEquals(1, emitted.size());
assertEquals(LogLevel.DEBUG, levels.get(0));
assertTrue(emitted.get(0), emitted.get(0).contains("moonrise worker pool size"));
assertTrue(emitted.get(0), emitted.get(0).contains(IllegalStateException.class.getName()));
assertTrue(emitted.get(0), emitted.get(0).contains("no such field"));
}
@Test
public void aThrowableWithNoMessageStillReportsItsClass() {
PregenDiagnostics.probeFailed("engine access", new NoClassDefFoundError());
assertEquals(1, emitted.size());
assertTrue(emitted.get(0), emitted.get(0).contains(NoClassDefFoundError.class.getName()));
assertTrue(emitted.get(0), emitted.get(0).contains("engine access"));
}
@Test
public void aMissingProbeNameAndThrowableStillProduceAReadableLine() {
PregenDiagnostics.probeFailed(null, null);
assertEquals(1, emitted.size());
assertTrue(emitted.get(0), emitted.get(0).contains("unnamed"));
assertTrue(emitted.get(0), emitted.get(0).contains("no throwable reported"));
}
@Test
public void percentSignsInAProbeNameAreNotTreatedAsFormatSpecifiers() {
PregenDiagnostics.probeFailed("heap at 95% headroom", new IllegalArgumentException("bad %s value"));
assertEquals(1, emitted.size());
assertTrue(emitted.get(0), emitted.get(0).contains("heap at 95% headroom"));
assertTrue(emitted.get(0), emitted.get(0).contains("bad %s value"));
}
}
@@ -0,0 +1,136 @@
package art.arcane.iris.core.pregenerator;
import org.junit.Test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class PregenSilentFailureContractTest {
@Test
public void noPregenSourceSwallowsAThrowableWithoutSayingAnything() throws IOException {
List<String> offenders = new ArrayList<>();
Path pregenRoot = sourceRoot().resolve("art/arcane/iris/core/pregenerator");
try (Stream<Path> sources = Files.walk(pregenRoot)) {
for (Path source : sources.filter(path -> path.toString().endsWith(".java")).toList()) {
String text = Files.readString(source);
if (text.contains("catch (Throwable ignored)") || text.contains("catch (Exception ignored)")) {
offenders.add(source.getFileName().toString());
}
}
}
assertEquals("silent catches on the pregen path: " + offenders, List.of(), offenders);
}
@Test
public void mantleCleanupFailureIsReportedWithItsStackTrace() throws IOException {
String cleanup = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
"private void cleanupMantleChunk(");
assertTrue(cleanup, cleanup.contains("IrisLogging.reportError("));
assertTrue(cleanup, cleanup.contains("catch (Throwable e)"));
}
@Test
public void aStrandedPluginChunkTicketIsReportedWithItsStackTrace() throws IOException {
String unload = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
"private void unloadChunkSafely(");
assertTrue(unload, unload.contains("removePluginChunkTicket"));
assertEquals(unload, 2, countOccurrences(unload, "IrisLogging.reportError("));
}
@Test
public void capabilityProbesLogThroughTheNamedDebugHelperRatherThanReportingErrors() throws IOException {
String async = read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java");
assertTrue(method(async, "private int resolveWorkerPoolThreads()").contains("PregenDiagnostics.probeFailed("));
assertTrue(method(async, "private int evictionWindow()").contains("PregenDiagnostics.probeFailed("));
assertTrue(method(async, "private Engine resolveMetricsEngine()").contains("PregenDiagnostics.probeFailed("));
}
@Test
public void theFoliaSubmitFallbackNamesTheFailureItIsFallingBackFrom() throws IOException {
String executor = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
"private class FoliaRegionExecutor");
assertTrue(executor, executor.contains("PregenDiagnostics.probeFailed("));
assertTrue(executor, executor.contains("falling back to a region task"));
}
@Test
public void backpressureProbesAnnounceWhyTheyFellBack() throws IOException {
String backpressure = read("art/arcane/iris/core/pregenerator/PregenMantleBackpressure.java");
assertTrue(method(backpressure, "private boolean isCancelled()").contains("PregenDiagnostics.probeFailed("));
assertTrue(method(backpressure, "private Mantle resolveMantle()").contains("PregenDiagnostics.probeFailed("));
}
@Test
public void medievalEngineResolutionAnnouncesWhyItFellBack() throws IOException {
String medieval = read("art/arcane/iris/core/pregenerator/methods/MedievalPregenMethod.java");
assertTrue(method(medieval, "private Engine resolveEngine()").contains("PregenDiagnostics.probeFailed("));
}
private static int countOccurrences(String text, String needle) {
int count = 0;
int index = text.indexOf(needle);
while (index >= 0) {
count++;
index = text.indexOf(needle, index + needle.length());
}
return count;
}
private static Path sourceRoot() throws IOException {
Path current;
try {
current = Path.of(PregenSilentFailureContractTest.class.getProtectionDomain()
.getCodeSource()
.getLocation()
.toURI());
} catch (URISyntaxException e) {
throw new IOException("Unable to resolve the core source root", e);
}
while (current != null && !Files.isDirectory(current.resolve("src/main/java"))) {
current = current.getParent();
}
if (current == null) {
throw new IOException("Unable to locate the core source root");
}
return current.resolve("src/main/java");
}
private static String read(String relativePath) throws IOException {
return Files.readString(sourceRoot().resolve(relativePath));
}
private static String method(String source, String signature) {
int start = source.indexOf(signature);
assertTrue("Missing source contract signature: " + signature, start >= 0);
int openBrace = source.indexOf('{', start);
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
int depth = 0;
for (int index = openBrace; index < source.length(); index++) {
char current = source.charAt(index);
if (current == '{') {
depth++;
} else if (current == '}') {
depth--;
if (depth == 0) {
return source.substring(start, index + 1);
}
}
}
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
}
}