fix: remove overly broad 'an error occurred' pattern

Per Greptile review feedback, the plain 'an error occurred' substring
match is too permissive and could trigger false failovers for
application-level errors that aren't transient provider failures.

Removed this pattern from isGenericProviderError() and updated tests
to verify that generic 'an error occurred' alone does NOT match,
while specific patterns like 'an unknown error occurred' still do.
This commit is contained in:
ShionElia 2026-03-18 10:40:45 +00:00
parent 627743aa38
commit 4be25a6866
2 changed files with 3 additions and 3 deletions

View File

@ -862,15 +862,16 @@ describe("classifyFailoverReason", () => {
});
it("classifies generic provider errors as timeout", () => {
expect(classifyFailoverReason("An unknown error occurred")).toBe("timeout");
expect(classifyFailoverReason("An error occurred")).toBe("timeout");
expect(classifyFailoverReason("Internal server error")).toBe("timeout");
expect(classifyFailoverReason("Service unavailable")).toBe("timeout");
// Case-insensitive
expect(classifyFailoverReason("AN UNKNOWN ERROR OCCURRED")).toBe("timeout");
expect(classifyFailoverReason("an error occurred while processing")).toBe("timeout");
// Wrapped in provider payload
expect(classifyFailoverReason('{"error":{"message":"An unknown error occurred"}}')).toBe(
"timeout",
);
// "an error occurred" alone should NOT match (too broad)
expect(classifyFailoverReason("An error occurred")).toBeNull();
expect(classifyFailoverReason("A validation error occurred")).toBeNull();
});
});

View File

@ -853,7 +853,6 @@ function isGenericProviderError(raw: string): boolean {
const lower = raw.toLowerCase();
return (
lower.includes("an unknown error occurred") ||
lower.includes("an error occurred") ||
lower.includes("internal server error") ||
lower.includes("service unavailable")
);