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
38 changes: 0 additions & 38 deletions app/api/room/create/route.tsx

This file was deleted.

1 change: 1 addition & 0 deletions app/api/sandbox/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function POST(request: Request): Promise<NextResponse> {

return {
maximumSizeInBytes: 100 * 1024 * 1024, // 100MB
addRandomSuffix: true,
};
},
onUploadCompleted: async () => {},
Expand Down
23 changes: 21 additions & 2 deletions lib/sandboxes/uploadSandboxFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function uploadSandboxFiles({
path?: string;
message?: string;
}): Promise<{ uploaded: UploadedFile[]; errors?: string[] }> {
const blobFiles = await Promise.all(
const results = await Promise.allSettled(
files.map(async (file) => {
const blob = await upload(file.name, file, {
access: "public",
Expand All @@ -47,6 +47,23 @@ export async function uploadSandboxFiles({
}),
);

const blobFiles: { url: string; name: string }[] = [];
const blobErrors: string[] = [];

results.forEach((r, i) => {
if (r.status === "fulfilled") {
blobFiles.push(r.value);
} else {
blobErrors.push(`${files[i].name}: ${r.reason?.message || "Upload failed"}`);
}
});

if (blobFiles.length === 0) {
throw new Error(
blobErrors[0] || "Failed to upload files to temporary storage",
);
}
Comment on lines +61 to +65
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don't drop the collected per-file errors on failure paths.

Line 63 only surfaces the first blobErrors entry when every blob upload fails, and Line 83 throws before the collected blobErrors/data.errors are combined. The batch diagnostics gathered above never reach callers in the failure cases where they matter most.

🛠️ Suggested fix
   if (blobFiles.length === 0) {
     throw new Error(
-      blobErrors[0] || "Failed to upload files to temporary storage",
+      blobErrors.length > 0
+        ? blobErrors.join("\n")
+        : "Failed to upload files to temporary storage",
     );
   }
@@
-  if (!response.ok || data.status === "error") {
-    throw new Error(data.error || "Failed to upload files");
-  }
-
   const allErrors = [...blobErrors, ...(data.errors || [])];
+  if (!response.ok || data.status === "error") {
+    throw new Error(
+      [data.error, ...allErrors].filter(Boolean).join("\n") ||
+        "Failed to upload files",
+    );
+  }

Also applies to: 82-86

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/sandboxes/uploadSandboxFiles.ts` around lines 61 - 65, When all blob
uploads fail the code currently throws only the first blobErrors entry and later
throws before merging blobErrors with data.errors; update the failure paths in
uploadSandboxFiles (the blobFiles branch and the later throw) to aggregate all
per-file diagnostics instead of losing them. Construct and throw a single
combined error (e.g., an AggregateError or Error whose message is
blobErrors.join("; ") plus any data.errors joined) so callers receive the full
list of per-file failures, and ensure you include both blobErrors and
data.errors when building that combined error.


const response = await fetch(`${NEW_API_BASE_URL}/api/sandboxes/files`, {
method: "POST",
headers: {
Expand All @@ -66,8 +83,10 @@ export async function uploadSandboxFiles({
throw new Error(data.error || "Failed to upload files");
}

const allErrors = [...blobErrors, ...(data.errors || [])];

return {
uploaded: data.uploaded || [],
errors: data.errors,
...(allErrors.length > 0 && { errors: allErrors }),
};
}
Loading