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,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);
}
}