fix: retry a malformed answer once and log the text around the fault

This commit is contained in:
2026-11-25 09:27:54 +01:00
parent 3b66030413
commit 44bb3fd46a
2 changed files with 37 additions and 1 deletions
+11
View File
@@ -280,3 +280,14 @@ func TestScanRun(t *testing.T) {
}
})
}
func TestParsePackageMalformedAnswer(t *testing.T) {
// What the first real scan hit: an object that closes early.
_, err := parsePackage([]byte(`{"is_error":false,"result":"{\"company\":\"Adyen\"}, \"title\":\"Engineer\"}"}`))
if !errors.Is(err, errBadAnswer) {
t.Fatalf("err = %v, want errBadAnswer so the assessment is retried", err)
}
if !strings.Contains(err.Error(), `Adyen`) {
t.Errorf("the error should quote the answer near the fault, got %v", err)
}
}