fix: log each failed file request once, expected outcomes at info

A streamer error such as repo_not_found produced three warnings: the
streamer's handleError, the API's streamer_fetch_failed and the API's
handleError. Expected client outcomes (repo_not_found, repository_expired,
file_not_found, github_app_access_required, ...) were all logged at warn,
which filled the admin Errors page.

- handleError picks the level with errorLogLevel: codes in
  EXPECTED_CLIENT_ERRORS with a 4xx status log at info; other 4xx (rate
  limits, token_expired, validation) stay warn and 5xx stay error.
- The streamer passes { internal: true }: expected outcomes drop to debug
  there because the API logs the request's end state. Faults keep their
  level and the streamer-side stack. Its direct 400 replies now go through
  handleError so they are logged too.
- The API no longer logs streamer_fetch_failed or streamer_zip_fetch_failed.
  The relayed error carries upstreamStatus, and when the streamer's coded
  reply shows it already logged the failure, the API logs it at info.

Every record keeps requestId, so the chain can still be found by request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 09:29:14 +00:00
1 parent 111870b6e2
commit c761fc6c17
7 files changed
+209 -71

No files matched your search

+13 -27
View File
@@ -59,14 +59,16 @@ function defaultMaskCandidateRegex(value: string): RegExp {
// generic 404. Without this, a corrupt cache, a 5xx from the streamer, an
// LFS pointer issue, and a missing file all surface to the user as the
// same `file_not_found` — which makes incidents impossible to triage.
// The request's handleError logs the result once. When the streamer answered,
// it already logged its side under the same requestId.
function streamerErrorToAnonymous(
err: Error & { response?: { statusCode?: number; body?: unknown } },
context: { repoId: string; filePath: string }
err: Error & { response?: { statusCode?: number; body?: unknown } }
): { error: AnonymousError; upstreamStatus?: number; upstreamBody?: string } {
const upstreamStatus = err?.response?.statusCode;
let errCode = "file_not_found";
let httpStatus = 404;
let upstreamBody: string | undefined;
let streamerCode = false;
if (err?.response?.body != null) {
try {
@@ -84,6 +86,7 @@ function streamerErrorToAnonymous(
const parsed = JSON.parse(upstreamBody);
if (parsed && typeof parsed.error === "string") {
errCode = parsed.error;
streamerCode = true;
}
} catch {
// body wasn't JSON — keep the default code
@@ -105,27 +108,14 @@ function streamerErrorToAnonymous(
httpStatus = 502;
}
logger.warn("streamer fetch failed", {
code: errCode,
const error = new AnonymousError(errCode, {
httpStatus,
repoId: context.repoId,
filePath: context.filePath,
upstreamStatus,
upstreamBody: upstreamBody?.slice(0, 500),
url: config.STREAMER_ENTRYPOINT
? join(config.STREAMER_ENTRYPOINT, "api")
: undefined,
err: serializeError(err),
cause: err,
});
return {
error: new AnonymousError(errCode, {
httpStatus,
cause: err,
}),
upstreamStatus,
upstreamBody,
};
error.upstreamStatus = upstreamStatus;
// A coded body comes from the streamer's handleError, which logged it.
error.upstreamLogged = streamerCode && typeof upstreamStatus === "number";
return { error, upstreamStatus, upstreamBody };
}
/**
@@ -434,7 +424,7 @@ export default class AnonymizedFile {
},
}));
content.on("error", err => {
const { error } = streamerErrorToAnonymous(err, { repoId: this.repository.repoId, filePath: this.anonymizedPath });
const { error } = streamerErrorToAnonymous(err);
void notifyOwnerAccessProblem(this.repository.owner.id, error, { kind: "repository", id: String(this.repository.model._id) });
});
return content;
@@ -493,7 +483,7 @@ export default class AnonymizedFile {
headersDone(true);
const { error } = streamerErrorToAnonymous(err as Error & {
response?: { statusCode?: number; body?: unknown };
}, { repoId: this.repository.repoId, filePath: this.anonymizedPath });
});
void notifyOwnerAccessProblem(this.repository.owner.id, error, { kind: "repository", id: String(this.repository.model._id) });
error.value = this;
throw error;
@@ -540,10 +530,6 @@ export default class AnonymizedFile {
const { error } = streamerErrorToAnonymous(
err as Error & {
response?: { statusCode?: number; body?: unknown };
},
{
repoId: this.repository.repoId,
filePath: this.anonymizedPath,
}
);
void notifyOwnerAccessProblem(this.repository.owner.id, error, { kind: "repository", id: String(this.repository.model._id) });