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
7 changes: 7 additions & 0 deletions .changeset/olive-heads-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Fix unclear error when assets upload session returns a `null` response

When deploying assets, if the Cloudflare API returns a `null` response object, Wrangler now provides a clear error message asking users to retry instead of failing with a confusing error.
32 changes: 32 additions & 0 deletions packages/wrangler/src/__tests__/deploy/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,5 +1195,37 @@ describe("deploy", () => {
});
await runWrangler("deploy --dispatch-namespace my-namespace");
});

it("should error when assets upload session response is null", async () => {
const assets = [{ filePath: "file-1.txt", content: "Content of file-1" }];
writeAssets(assets);
writeWranglerConfig({
assets: { directory: "assets" },
});

// Mock the AUS endpoint to return a null result
msw.use(
http.post(
`*/accounts/some-account-id/workers/scripts/test-name/assets-upload-session`,
() => {
return HttpResponse.json(
{
success: true,
errors: [],
messages: [],
result: null,
},
{ status: 201 }
);
}
)
);

await expect(
runWrangler("deploy")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: An unexpected response has been received from the Cloudflare API for assets upload. Please try again.]`
);
});
});
});
21 changes: 15 additions & 6 deletions packages/wrangler/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,24 @@ export const syncAssets = async (

// 2. fetch buckets w/ hashes
logger.info("🌀 Starting asset upload...");
const initializeAssetsResponse = await fetchResult<InitializeAssetsResponse>(
complianceConfig,
url,
{
const initializeAssetsResponse =
await fetchResult<InitializeAssetsResponse | null>(complianceConfig, url, {
headers: { "Content-Type": "application/json" },
method: "POST",
body: JSON.stringify({ manifest: manifest }),
}
);
});

// In the past we've seen the endpoint return that incorrectly doesn't contain
// a null response (see: https://github.com/cloudflare/workers-sdk/issues/9465).
// So just to be extra sure here we check the object and provide a clear error message to the user
// if it is falsy.
if (!initializeAssetsResponse) {
throw new FatalError(
"An unexpected response has been received from the Cloudflare API for assets upload. Please try again.",
1,
{ telemetryMessage: true }
Comment thread
dario-piotrowicz marked this conversation as resolved.
Resolved
);
}

// if nothing to upload, return
if (initializeAssetsResponse.buckets.flat().length === 0) {
Expand Down
Loading