Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ export function SummaryTab({
specialSettings && specialSettings.length > 0 ? JSON.stringify(specialSettings, null, 2) : null;
const isFake200PostStreamFailure =
typeof errorMessage === "string" && errorMessage.startsWith("FAKE_200_");
const fake200Code =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] [TEST-EDGE-CASE] No unit coverage for new "FAKE_200_*: detail" parsing

Why this is a problem: New logic now relies on errorMessage.split(": ")[0] to recover the FAKE_200 code for i18n lookups:

  • src/app/[locale]/dashboard/logs/_components/error-details-dialog/components/SummaryTab.tsx:72-77
  • src/app/[locale]/dashboard/logs/_components/provider-chain-popover.tsx:134-138 and :549-552

Existing UI tests only exercise the raw code format (no ": detail" suffix), so a delimiter/format regression will slip:

  • src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx:400-414
  • src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx:274-291

This conflicts with CLAUDE.md:

  • 2. **Test Coverage** - All new features must have unit test coverage of at least 80%

Suggested fix: Add/extend tests to cover the new "CODE: detail" format.

// src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx
test("renders fake-200 detected reason when errorMessage uses CODE: detail", () => {
  const html = renderWithIntl(
    <ErrorDetailsDialog
      externalOpen
      statusCode={502}
      errorMessage={"FAKE_200_JSON_ERROR_MESSAGE_NON_EMPTY: Invalid API key"}
      providerChain={null}
      sessionId={null}
    />
  );

  expect(html).toContain("Detected reason: JSON has non-empty error.message");
});
// src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx
test("renders fake-200 detected reason when chain errorMessage uses CODE: detail", () => {
  const html = renderWithIntl(
    <ProviderChainPopover
      chain={[
        {
          id: 1,
          name: "p1",
          reason: "retry_failed",
          statusCode: 502,
          errorMessage: "FAKE_200_JSON_ERROR_MESSAGE_NON_EMPTY: Invalid API key",
        },
      ]}
      finalProvider="p1"
    />
  );

  expect(html).toContain("Detected reason: JSON has non-empty error.message");
});

isFake200PostStreamFailure && errorMessage ? errorMessage.split(": ")[0] : errorMessage;
const fake200Reason =
isFake200PostStreamFailure && typeof errorMessage === "string"
? t(getFake200ReasonKey(errorMessage, "fake200Reasons"))
isFake200PostStreamFailure && fake200Code
? t(getFake200ReasonKey(fake200Code, "fake200Reasons"))
: null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ export function ProviderChainPopover({
const hasFake200PostStreamFailure = chain.some(
(item) => typeof item.errorMessage === "string" && item.errorMessage.startsWith("FAKE_200_")
);
const fake200CodeForDisplay = chain.find(
(item) => typeof item.errorMessage === "string" && item.errorMessage.startsWith("FAKE_200_")
)?.errorMessage;
const fake200CodeForDisplay = chain
.find(
(item) => typeof item.errorMessage === "string" && item.errorMessage.startsWith("FAKE_200_")
)
?.errorMessage?.split(": ")[0];

// Calculate actual request count (excluding intermediate states)
const requestCount = chain.filter(isActualRequest).length;
Expand Down Expand Up @@ -545,7 +547,7 @@ export function ProviderChainPopover({
{t("logs.details.fake200DetectedReason", {
reason: t(
getFake200ReasonKey(
item.errorMessage,
item.errorMessage.split(": ")[0],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential runtime error if item.errorMessage doesn't contain ": "

The code assumes all fake 200 errors have the new format, but old errors or errors without detail will cause .split(": ")[0] to return the full string. Line 138 handles this correctly by using optional chaining (?.errorMessage?.split), but this line doesn't.

Suggested change
item.errorMessage.split(": ")[0],
item.errorMessage?.split(": ")[0] ?? item.errorMessage,
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/[locale]/dashboard/logs/_components/provider-chain-popover.tsx
Line: 550

Comment:
potential runtime error if `item.errorMessage` doesn't contain ": "

The code assumes all fake 200 errors have the new format, but old errors or errors without detail will cause `.split(": ")[0]` to return the full string. Line 138 handles this correctly by using optional chaining (`?.errorMessage?.split`), but this line doesn't.

```suggestion
                                  item.errorMessage?.split(": ")[0] ?? item.errorMessage,
```

How can I resolve this? If you propose a fix, please make it concise.

"logs.details.fake200Reasons"
)
),
Expand Down
4 changes: 2 additions & 2 deletions src/app/v1/_lib/proxy/response-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async function finalizeDeferredStreamingFinalizationIfNeeded(
} else {
effectiveStatusCode = 502;
}
errorMessage = detected.code;
errorMessage = detected.detail ? `${detected.code}: ${detected.detail}` : detected.code;
} else if (!streamEndedNormally) {
effectiveStatusCode = clientAborted ? 499 : 502;
errorMessage = clientAborted ? "CLIENT_ABORTED" : (abortReason ?? "STREAM_ABORTED");
Expand Down Expand Up @@ -330,7 +330,7 @@ async function finalizeDeferredStreamingFinalizationIfNeeded(
attemptNumber: meta.attemptNumber,
statusCode: effectiveStatusCode,
statusCodeInferred,
errorMessage: detected.code,
errorMessage: detected.detail ? `${detected.code}: ${detected.detail}` : detected.code,
});

return { effectiveStatusCode, errorMessage, providerIdForPersistence };
Expand Down
Loading