Files
PaperClipAI/server/src/storage/failure-diagnostics.ts
T
Devin Foley 1a36195868 fix(storage): name the S3 read when a response body is cut off (#19284)
Record read_object_body with HTTP status, S3 request id and attempts when a GetObject body stream errors after send() resolved, and add the storage fields to run failure execution diagnostics. Diagnostics only; no retry behavior changes.
2026-11-05 16:19:26 -08:00

36 lines
1.2 KiB
TypeScript

// Server-only, fixed-shape storage failure details for error reporting. The
// provider that owns the protocol normalizes them; reporting reads only this
// record and never the provider's error payload.
export type StorageFailureOperation =
| "put_object"
| "get_object"
| "read_object_body"
| "head_object"
| "delete_object"
| "create_multipart_upload"
| "upload_part"
| "complete_multipart_upload";
export interface StorageFailureDiagnostics {
provider: "s3";
operation: StorageFailureOperation;
errorCode: string;
httpStatus: number | null;
requestId: string | null;
attempts: number | null;
}
const recorded = new WeakMap<object, Readonly<StorageFailureDiagnostics>>();
/** Keep the first record: it names the call that actually failed. */
export function recordStorageFailure(error: unknown, diagnostics: StorageFailureDiagnostics): void {
if (!error || typeof error !== "object" || recorded.has(error)) return;
recorded.set(error, Object.freeze({ ...diagnostics }));
}
export function storageFailureDiagnosticsFor(error: unknown): Readonly<StorageFailureDiagnostics> | null {
if (!error || typeof error !== "object") return null;
return recorded.get(error) ?? null;
}