fix: keep every thrown error code in the logs

The logger keeps errorCode only for allowlisted codes, and so does the
collector (sanitize.vrl). Both lists are maintained by hand, so codes
added since then were dropped and logged as a bare 400. Among them:
invalid_billing_expiration (billingError), invalid_auth_state
(appError), streamer_unreachable, github_unavailable, user_banned and
most billing and GitHub App codes, 41 in all.

scripts/generate-log-diagnostics.js now collects the codes passed to
AnonymousError, billingError and appError, plus codes assigned to an
errCode/code variable. It writes them to LOG_THROWN_ERROR_CODES, which
the logger accepts, and appends them to the collector's errorCode
allowlist. A test fails when a thrown code is missing from either list.

Regenerating also refreshes source function names that had gone stale
(jsDelivrFileUrl, ownerGitHubAccessRequired, ...), whose stack frames
the collector was dropping.

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:16:35 +00:00
1 parent a4f65e7d30
commit 63343c871c
5 files changed
+110 -8

No files matched your search

+13
View File
@@ -142,6 +142,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"getToken",
"getTokenGateResetAt",
"octokit",
"ownerGitHubAccessRequired",
"rateLimitDetail",
"resolveRepositoryToken",
"run",
@@ -160,6 +161,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"getToken",
"getTokenGateResetAt",
"octokit",
"ownerGitHubAccessRequired",
"rateLimitDetail",
"resolveRepositoryToken",
"run",
@@ -1643,6 +1645,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"admitResolvedBytes",
"assertActive",
"assertDownloadUrl",
"assertHost",
"cached",
"confirmOwnerAccess",
"deferredRawDownload",
@@ -1651,6 +1654,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"downloadFile",
"downloadFileViaRaw",
"downloadRaw",
"downloadViaJsDelivr",
"downloadWithFallback",
"fallbackToRaw",
"fetchContent",
@@ -1663,9 +1667,12 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"githubRawFileUrl",
"iterateFiles",
"iterateTreeBatches",
"jsDelivrFileUrl",
"lfsPointerGuard",
"normalize",
"pMap",
"produce",
"rejectLfsPointer",
"resolve",
"resolveLfsPointer",
"stopSourceOnDestroy",
@@ -1679,6 +1686,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"admitResolvedBytes",
"assertActive",
"assertDownloadUrl",
"assertHost",
"cached",
"confirmOwnerAccess",
"deferredRawDownload",
@@ -1687,6 +1695,7 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"downloadFile",
"downloadFileViaRaw",
"downloadRaw",
"downloadViaJsDelivr",
"downloadWithFallback",
"fallbackToRaw",
"fetchContent",
@@ -1699,9 +1708,12 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
"githubRawFileUrl",
"iterateFiles",
"iterateTreeBatches",
"jsDelivrFileUrl",
"lfsPointerGuard",
"normalize",
"pMap",
"produce",
"rejectLfsPointer",
"resolve",
"resolveLfsPointer",
"stopSourceOnDestroy",
@@ -2927,3 +2939,4 @@ export const LOG_SOURCE_FUNCTIONS: Record<string, readonly string[]> = {
};
export const LOG_ERROR_TYPES = ["Error","TypeError","RangeError","ReferenceError","SyntaxError","URIError","EvalError","AggregateError","AnonymousError","HTTPError","RequestError","MongoServerError","MongoNetworkError","MongoServerSelectionError","ValidationError","TimeoutError","AbortError","UnknownError"];
export const LOG_ROUTES = ["/","other","/dashboard","/anonymize","/healthcheck","/api/healthcheck","/api","/api/download","/api/stat","/api/stat/history","/api/options","/api/message","/api/user","/api/user/quota","/api/user/dashboard","/api/repo","/api/anonymize-preview","/api/admin/overview","/api/admin/performance","/api/admin/errors","/api/admin/errors/stats","/api/admin/queues","/api/admin/queues/metrics","/github/app/webhook","/api/repo/:repoId","/api/repo/:repoId/file/:path","/api/repo/:repoId/files","/api/repo/:repoId/files/counts","/api/repo/:repoId/files/search","/api/repo/:repoId/zip","/api/repo/:repoId/options","/api/repo/:repoId/refresh","/api/repo/:repoId/coauthors","/api/repo/:repoId/extend","/api/repo/:owner/:repo","/api/repo/:owner/:repo/tree","/api/repo/:owner/:repo/file","/api/repo/:owner/:repo/readme","/api/repo/:owner/:repo/branches","/w/:repoId/:path","/r/:repoId/:path","/api/pr/:id/:path","/api/gist/:id/:path","/assets/:path","/github/:action","/api/admin/:action","/api/user/:action","/api/repo/:id/file/:path","/api/repo/:id/files/counts","/api/repo/:id/files/search","/api/repo/:id/files","/api/repo/:id/zip","/api/repo/:id","/viewer/:id/:path","/api/billing","/api/billing/draft","/api/billing/draft/:id","/api/billing/checkout","/api/billing/portal","/api/billing/refresh","/api/billing/webhook","/api/conferences/plans","/profile","/conference/:id"];
export const LOG_THROWN_ERROR_CODES = ["another_login_required","billing_address_missing","billing_already_paid","billing_busy","billing_checkout_disabled","billing_checkout_in_progress","billing_city_missing","billing_country_missing","billing_customer_mismatch","billing_draft_not_found","billing_email_missing","billing_invalid_conference","billing_invalid_draft","billing_invalid_purchase","billing_invalid_repository_size","billing_invalid_review_window","billing_missing","billing_name_missing","billing_plan_change_not_supported","billing_plan_unavailable","billing_price_misconfigured","billing_recovery_required","billing_review_window_locked","billing_subscription_exists","billing_unavailable","billing_zip_missing","branch_not_found","branch_not_specified","cache_busy","cache_miss","cannot_coauthor_self","commit_not_found","commit_not_specified","conf_end_date_invalid","conf_end_date_missing","conf_id_missing","conf_id_used","conf_name_missing","conf_not_activated","conf_not_found","conf_start_date_invalid","conf_start_date_missing","conference_not_found","conference_payment_required","connection_changed","download_not_enabled","expiration_limit_reached","file_listing_too_large","file_not_accessible","file_not_found","file_not_supported","file_too_big","folder_not_supported","gistId_already_used","gistId_not_specified","gist_expired","gist_not_available","gist_not_found","gist_not_ready","github_app_access_required","github_app_authorization_cancelled","github_app_disabled","github_app_permissions_invalid","github_app_reconnect_required","github_app_refresh_busy","github_grant_revocation_failed","github_identity_mismatch","github_oauth_required","github_rate_limit_exceeded","github_unavailable","github_user_not_found","invalid_auth_state","invalid_billing_expiration","invalid_commit_format","invalid_connection","invalid_cursor","invalid_gistId","invalid_github_path","invalid_path","invalid_plan","invalid_preserve_files_format","invalid_project_name","invalid_pullRequestId","invalid_repo","invalid_repoId","invalid_request","invalid_settings","invalid_sort","invalid_status","invalid_terms_format","invalid_token_id","invalid_token_options","is_removed","not_authorized","not_connected","not_owner","oauth_resources_remaining","options_not_provided","page_not_activated","page_not_supported_on_different_branch","path_not_defined","path_not_specified","pullRequestId_already_used","pullRequestId_is_not_a_number","pullRequestId_not_specified","pull_request_expired","pull_request_not_available","pull_request_not_found","pull_request_not_ready","quota_exceeded","quota_repository_limit","quota_storage_limit","rate_limited","readme_not_available","repoId_already_used","repoId_not_defined","repoUrl_not_defined","repo_access_limited","repo_empty","repo_not_accessible","repo_not_found","repo_saml_enforcement","repository_archived","repository_busy","repository_changed","repository_expired","repository_job_cancelled","repository_not_accessible","repository_not_ready","repository_not_specified","repository_tree_incomplete","repository_tree_too_large","s3_config_not_provided","source_not_provided","storage_delete_failed","storage_write_size_mismatch","streamer_unreachable","streamer_upstream_error","submodule_not_available","subscription_required_for_never_expiration","terms_not_specified","token_expired","token_limit_reached","unable_to_connect_user","unable_to_download","upstream_error","user_banned","user_not_found","username_not_defined","zip_not_available","zip_unsafe_entry_path"];
+5 -4
View File
@@ -1,7 +1,7 @@
import { ANONYMIZATION_ERRORS } from "./anonymization-errors";
import { requestReproduction, safeReproductionPath } from "./log-reproduction";
import { safeDiagnosticFields, errorDiagnostics } from "./log-diagnostics";
import { LOG_ROUTES } from "./log-diagnostic-schema";
import { LOG_ROUTES, LOG_THROWN_ERROR_CODES } from "./log-diagnostic-schema";
import { LOG_MODULES, ERROR_CODES, LOG_EVENTS } from "./log-schema";
import { randomUUID } from "crypto";
import { logContext, validTraceId } from "./log-context";
@@ -17,8 +17,9 @@ const events: Record<string, string> = {
"process heartbeat": "process_heartbeat", "job started": "job_started", "job completed": "job_completed",
"job failed": "job_failed", "job stalled": "job_stalled", "queue heartbeat": "queue_heartbeat",
};
const errorCodes = new Set([
...ERROR_CODES, ...ANONYMIZATION_ERRORS, "zip_unsafe_entry_path",
// LOG_THROWN_ERROR_CODES is generated from the codes the source throws.
export const LOG_ERROR_CODES: ReadonlySet<string> = new Set([
...ERROR_CODES, ...ANONYMIZATION_ERRORS, ...LOG_THROWN_ERROR_CODES, "zip_unsafe_entry_path",
"repo_renamed", "preparation_interrupted", "commit_not_found", "zip_not_available", "token_refresh_failed", "quota_exceeded", "quota_repository_limit", "quota_storage_limit", "github_rate_limit_exceeded", "github_app_reconnect_required", "github_token_invalid",
"repository_expired", "repository_not_ready", "repository_not_found", "repository_job_cancelled",
"ECONNRESET", "ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND", "EPIPE", "ABORT_ERR",
@@ -57,7 +58,7 @@ export function logRecord(level: string, module: string, args: unknown[]) {
}
if (Number.isSafeInteger(context.attempt)) record.attempt = context.attempt;
for (const key of LOG_NUMBERS) if (typeof details[key] === "number" && Number.isFinite(details[key])) record[key] = details[key];
const code = [details.code, details.message].find(value => typeof value === "string" && errorCodes.has(value));
const code = [details.code, details.message].find(value => typeof value === "string" && LOG_ERROR_CODES.has(value));
if (code) record.errorCode = code;
if (allowed(["protocol", "credentials", "port", "host"], details.reason)) record.reason = details.reason;
if (allowed(["parse", "find_grant_owners", "reconcile_grant", "persist_installation_block", "reconcile_installation"], details.phase)) record.phase = details.phase;