Fix #19: Fehlergrund bei fehlgeschlagenem KI-Aufruf im Begründungsbereich anzeigen
- DocumentCompletionEvent um optionales Feld failureMessage erweitert - DocumentProcessingCoordinator leitet Fehlermeldung bei Fehler-Status durch - GuiBatchRunResultRow um aiFailureMessage (Optional<String>) ergänzt - GuiBatchRunCoordinator.toRow() befüllt aiFailureMessage aus dem Event - GuiBatchRunTab.buildDetailText() zeigt bei fehlendem Reasoning und vorhandenem Fehlergrund: "⚠ Fehler: <Meldung>" vor dem Hinweistext - Alle Tests angepasst und neue Unit-Tests für aiFailureMessage ergänzt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+3
@@ -506,6 +506,8 @@ public final class GuiBatchRunCoordinator {
|
||||
? Optional.empty() : Optional.of(event.resolvedDate());
|
||||
Optional<String> reasoning = event.aiReasoning() == null || event.aiReasoning().isBlank()
|
||||
? Optional.empty() : Optional.of(event.aiReasoning());
|
||||
Optional<String> failureMessage = event.failureMessage() == null || event.failureMessage().isBlank()
|
||||
? Optional.empty() : Optional.of(event.failureMessage());
|
||||
Duration duration = event.processingDuration();
|
||||
return new GuiBatchRunResultRow(
|
||||
event.originalFileName(),
|
||||
@@ -514,6 +516,7 @@ public final class GuiBatchRunCoordinator {
|
||||
finalName,
|
||||
date,
|
||||
reasoning,
|
||||
failureMessage,
|
||||
duration);
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -34,6 +34,9 @@ import de.gecheckt.pdf.umbenenner.domain.model.DocumentFingerprint;
|
||||
* rename; empty otherwise
|
||||
* @param aiReasoning the AI reasoning shown in the side panel; empty when no
|
||||
* reasoning is available for this row
|
||||
* @param aiFailureMessage eine lesbare Fehlerbeschreibung, wenn der KI-Aufruf oder die
|
||||
* Verarbeitung fehlgeschlagen ist; leer bei Erfolg und
|
||||
* übersprungenen Dokumenten
|
||||
* @param processingDuration wall-clock duration spent on the candidate in this run;
|
||||
* never {@code null} and never negative
|
||||
* @param resetPending {@code true} when the document's persistence status has been
|
||||
@@ -46,6 +49,7 @@ public record GuiBatchRunResultRow(
|
||||
Optional<String> finalFileName,
|
||||
Optional<LocalDate> resolvedDate,
|
||||
Optional<String> aiReasoning,
|
||||
Optional<String> aiFailureMessage,
|
||||
Duration processingDuration,
|
||||
boolean resetPending) {
|
||||
|
||||
@@ -79,6 +83,7 @@ public record GuiBatchRunResultRow(
|
||||
finalFileName = finalFileName == null ? Optional.empty() : finalFileName;
|
||||
resolvedDate = resolvedDate == null ? Optional.empty() : resolvedDate;
|
||||
aiReasoning = aiReasoning == null ? Optional.empty() : aiReasoning;
|
||||
aiFailureMessage = aiFailureMessage == null ? Optional.empty() : aiFailureMessage;
|
||||
Objects.requireNonNull(processingDuration, "processingDuration must not be null");
|
||||
if (processingDuration.isNegative()) {
|
||||
throw new IllegalArgumentException("processingDuration must not be negative");
|
||||
@@ -97,6 +102,8 @@ public record GuiBatchRunResultRow(
|
||||
* empty)
|
||||
* @param aiReasoning the AI reasoning text; may be {@code null} (treated as
|
||||
* empty)
|
||||
* @param aiFailureMessage eine lesbare Fehlerbeschreibung bei Fehler; may be
|
||||
* {@code null} (treated as empty)
|
||||
* @param processingDuration the wall-clock processing duration; never {@code null}
|
||||
*/
|
||||
public GuiBatchRunResultRow(
|
||||
@@ -106,9 +113,10 @@ public record GuiBatchRunResultRow(
|
||||
Optional<String> finalFileName,
|
||||
Optional<LocalDate> resolvedDate,
|
||||
Optional<String> aiReasoning,
|
||||
Optional<String> aiFailureMessage,
|
||||
Duration processingDuration) {
|
||||
this(originalFileName, fingerprint, status, finalFileName, resolvedDate, aiReasoning,
|
||||
processingDuration, false);
|
||||
aiFailureMessage, processingDuration, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,6 +139,7 @@ public record GuiBatchRunResultRow(
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Duration.ZERO,
|
||||
true);
|
||||
}
|
||||
|
||||
+6
-1
@@ -899,7 +899,11 @@ public final class GuiBatchRunTab {
|
||||
builder.append('\n');
|
||||
row.aiReasoning().ifPresentOrElse(
|
||||
reasoning -> builder.append(reasoning),
|
||||
() -> builder.append(NO_REASONING_TEXT));
|
||||
() -> {
|
||||
row.aiFailureMessage().ifPresent(msg ->
|
||||
builder.append("\u26A0 Fehler: ").append(msg).append("\n\n"));
|
||||
builder.append(NO_REASONING_TEXT);
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -1012,6 +1016,7 @@ public final class GuiBatchRunTab {
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.of(message),
|
||||
Optional.empty(),
|
||||
Duration.ZERO,
|
||||
false);
|
||||
upsertResultRowByFingerprint(missingRow);
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ class GuiBatchRunCoordinatorMiniRunTest {
|
||||
observer.onRunStarted(new RunId("mini-1"), 1);
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"a.pdf", FP1, DocumentCompletionStatus.SUCCESS,
|
||||
"2026-01-01 - Test.pdf", null, null, Duration.ofMillis(50)));
|
||||
"2026-01-01 - Test.pdf", null, null, null, Duration.ofMillis(50)));
|
||||
observer.onRunEnded(new RunSummary(1, 0, 0));
|
||||
return GuiBatchRunLaunchOutcome.completed();
|
||||
};
|
||||
|
||||
+9
-8
@@ -77,10 +77,10 @@ class GuiBatchRunCoordinatorTest {
|
||||
observer.onRunStarted(new RunId("run-1"), 2);
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
|
||||
"2026-03-01 - Titel.pdf", LocalDate.of(2026, 3, 1), "gut", Duration.ofMillis(20)));
|
||||
"2026-03-01 - Titel.pdf", LocalDate.of(2026, 3, 1), "gut", null, Duration.ofMillis(20)));
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"b.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_PERMANENT,
|
||||
null, null, null, Duration.ofMillis(10)));
|
||||
null, null, null, null, Duration.ofMillis(10)));
|
||||
observer.onRunEnded(new RunSummary(1, 1, 0));
|
||||
return GuiBatchRunLaunchOutcome.completed();
|
||||
};
|
||||
@@ -119,7 +119,7 @@ class GuiBatchRunCoordinatorTest {
|
||||
observer.onRunStarted(new RunId("run-skip"), 1);
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"c.pdf", DUMMY_FP, DocumentCompletionStatus.SKIPPED,
|
||||
null, null, null, Duration.ofMillis(5)));
|
||||
null, null, null, null, Duration.ofMillis(5)));
|
||||
observer.onRunEnded(new RunSummary(0, 0, 1));
|
||||
return GuiBatchRunLaunchOutcome.completed();
|
||||
};
|
||||
@@ -317,7 +317,7 @@ class GuiBatchRunCoordinatorTest {
|
||||
|
||||
private static GuiBatchRunResultRow row(DocumentCompletionStatus status) {
|
||||
return new GuiBatchRunResultRow(
|
||||
"x.pdf", DUMMY_FP, status, null, null, null, Duration.ofMillis(1));
|
||||
"x.pdf", DUMMY_FP, status, null, null, null, null, Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
private static GuiBatchRunCoordinator.Listener noOpListener() {
|
||||
@@ -358,7 +358,7 @@ class GuiBatchRunCoordinatorTest {
|
||||
BatchRunProgressObserver noOp = BatchRunProgressObserver.noOp();
|
||||
noOp.onRunStarted(new RunId("x"), 0);
|
||||
noOp.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS, null, null, null, Duration.ZERO));
|
||||
"a.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS, null, null, null, null, Duration.ZERO));
|
||||
noOp.onRunEnded(new RunSummary(0, 0, 0));
|
||||
assertSame(noOp, BatchRunProgressObserver.noOp());
|
||||
assertFalse(BatchRunCancellationToken.neverCancelled().isCancellationRequested());
|
||||
@@ -370,12 +370,12 @@ class GuiBatchRunCoordinatorTest {
|
||||
void resultRow_rejectsInvalidInput() {
|
||||
try {
|
||||
new GuiBatchRunResultRow(" ", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ZERO);
|
||||
null, null, null, null, Duration.ZERO);
|
||||
throw new AssertionError("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) { /* ok */ }
|
||||
try {
|
||||
new GuiBatchRunResultRow("x.pdf", DUMMY_FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ofSeconds(-1));
|
||||
null, null, null, null, Duration.ofSeconds(-1));
|
||||
throw new AssertionError("expected IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) { /* ok */ }
|
||||
}
|
||||
@@ -384,9 +384,10 @@ class GuiBatchRunCoordinatorTest {
|
||||
void resultRow_optionalHoldersNormaliseNullToEmpty() {
|
||||
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
|
||||
"x.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_PERMANENT,
|
||||
null, null, null, Duration.ZERO);
|
||||
null, null, null, null, Duration.ZERO);
|
||||
assertNull(row.finalFileName().orElse(null));
|
||||
assertNull(row.resolvedDate().orElse(null));
|
||||
assertNull(row.aiReasoning().orElse(null));
|
||||
assertNull(row.aiFailureMessage().orElse(null));
|
||||
}
|
||||
}
|
||||
|
||||
+32
-8
@@ -35,6 +35,7 @@ class GuiBatchRunResultRowTest {
|
||||
Optional.of("2026-01-01 - Titel.pdf"),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
Duration.ofMillis(100));
|
||||
assertEquals("test.pdf", row.originalFileName());
|
||||
assertEquals(FP, row.fingerprint());
|
||||
@@ -46,45 +47,46 @@ class GuiBatchRunResultRowTest {
|
||||
void construction_nullOriginalFileName_throws() {
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
new GuiBatchRunResultRow(null, FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ZERO));
|
||||
null, null, null, null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_blankOriginalFileName_throws() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new GuiBatchRunResultRow(" ", FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ZERO));
|
||||
null, null, null, null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_nullFingerprint_throws() {
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
new GuiBatchRunResultRow("test.pdf", null, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ZERO));
|
||||
null, null, null, null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_nullStatus_throws() {
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
new GuiBatchRunResultRow("test.pdf", FP, null,
|
||||
null, null, null, Duration.ZERO));
|
||||
null, null, null, null, Duration.ZERO));
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_negativeDuration_throws() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
new GuiBatchRunResultRow("test.pdf", FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Duration.ofSeconds(-1)));
|
||||
null, null, null, null, Duration.ofSeconds(-1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_nullOptionals_normalisedToEmpty() {
|
||||
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
|
||||
"test.pdf", FP, DocumentCompletionStatus.FAILED_PERMANENT,
|
||||
null, null, null, Duration.ZERO);
|
||||
null, null, null, null, Duration.ZERO);
|
||||
assertTrue(row.finalFileName().isEmpty());
|
||||
assertTrue(row.resolvedDate().isEmpty());
|
||||
assertTrue(row.aiReasoning().isEmpty());
|
||||
assertTrue(row.aiFailureMessage().isEmpty());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -144,12 +146,13 @@ class GuiBatchRunResultRowTest {
|
||||
GuiBatchRunResultRow original = new GuiBatchRunResultRow(
|
||||
"test.pdf", FP, DocumentCompletionStatus.SUCCESS,
|
||||
Optional.of("2026-01-01 - Titel.pdf"), Optional.empty(), Optional.empty(),
|
||||
Duration.ofMillis(42));
|
||||
Optional.empty(), Duration.ofMillis(42));
|
||||
GuiBatchRunResultRow marker = GuiBatchRunResultRow.resetMarker(original);
|
||||
|
||||
assertTrue(marker.finalFileName().isEmpty());
|
||||
assertTrue(marker.resolvedDate().isEmpty());
|
||||
assertTrue(marker.aiReasoning().isEmpty());
|
||||
assertTrue(marker.aiFailureMessage().isEmpty());
|
||||
assertEquals(Duration.ZERO, marker.processingDuration());
|
||||
}
|
||||
|
||||
@@ -173,12 +176,33 @@ class GuiBatchRunResultRowTest {
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// aiFailureMessage
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
void construction_withFailureMessage_isPresent() {
|
||||
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
|
||||
"test.pdf", FP, DocumentCompletionStatus.FAILED_RETRYABLE,
|
||||
null, null, null, Optional.of("KI-Timeout"), Duration.ofMillis(10));
|
||||
assertTrue(row.aiFailureMessage().isPresent());
|
||||
assertEquals("KI-Timeout", row.aiFailureMessage().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void construction_withoutFailureMessage_isEmpty() {
|
||||
GuiBatchRunResultRow row = new GuiBatchRunResultRow(
|
||||
"test.pdf", FP, DocumentCompletionStatus.SUCCESS,
|
||||
null, null, null, Optional.empty(), Duration.ofMillis(10));
|
||||
assertTrue(row.aiFailureMessage().isEmpty());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Helper
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private static GuiBatchRunResultRow row(DocumentCompletionStatus status) {
|
||||
return new GuiBatchRunResultRow(
|
||||
"file.pdf", FP, status, null, null, null, Duration.ofMillis(1));
|
||||
"file.pdf", FP, status, null, null, null, null, Duration.ofMillis(1));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -188,6 +188,7 @@ class GuiBatchRunTabSelectionSmokeTest {
|
||||
"2026-01-01 - Titel.pdf",
|
||||
java.time.LocalDate.of(2026, 1, 1),
|
||||
"reasoning",
|
||||
null,
|
||||
Duration.ofMillis(5)));
|
||||
observer.onRunEnded(new RunSummary(1, 0, 0));
|
||||
return GuiBatchRunLaunchOutcome.completed();
|
||||
@@ -286,7 +287,7 @@ class GuiBatchRunTabSelectionSmokeTest {
|
||||
private static GuiBatchRunResultRow row(String name, DocumentFingerprint fp,
|
||||
DocumentCompletionStatus status) {
|
||||
return new GuiBatchRunResultRow(name, fp, status,
|
||||
Optional.empty(), Optional.empty(), Optional.empty(), Duration.ofMillis(1));
|
||||
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
private void runOnFx(Runnable action) throws InterruptedException {
|
||||
|
||||
+3
-2
@@ -101,13 +101,14 @@ class GuiBatchRunTabSmokeTest {
|
||||
"2026-03-01 - Titel.pdf",
|
||||
LocalDate.of(2026, 3, 1),
|
||||
"gut begründet",
|
||||
null,
|
||||
Duration.ofMillis(42)));
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"b.pdf", DUMMY_FP, DocumentCompletionStatus.FAILED_RETRYABLE,
|
||||
null, null, null, Duration.ofMillis(10)));
|
||||
null, null, null, null, Duration.ofMillis(10)));
|
||||
observer.onDocumentCompleted(new DocumentCompletionEvent(
|
||||
"c.pdf", DUMMY_FP, DocumentCompletionStatus.SKIPPED,
|
||||
null, null, null, Duration.ofMillis(5)));
|
||||
null, null, null, null, Duration.ofMillis(5)));
|
||||
observer.onRunEnded(new RunSummary(1, 1, 1));
|
||||
return GuiBatchRunLaunchOutcome.completed();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user