Skip to content
Open
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/r2-bucket-list-no-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Allow `wrangler r2 bucket list` to run without a valid Wrangler config

This is an account-level command and does not require parsing `wrangler.toml`/`wrangler.jsonc`. Previously, an invalid local config could prevent listing buckets, making it harder to fix the config.
54 changes: 54 additions & 0 deletions packages/wrangler/src/__tests__/r2/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,60 @@ describe("r2", () => {
creation_date: 01-01-2001"
`);
});

it("should list buckets even if the local wrangler config is invalid", async () => {
writeWranglerConfig(
{
r2_buckets: [
{
binding: "BUCKET",
bucket_name: "Invalid_Bucket",
},
],
},
"./wrangler.jsonc"
);

const mockBuckets = [
{
name: "bucket-1-local-once",
creation_date: "01-01-2001",
},
{
name: "bucket-2-local-once",
creation_date: "01-01-2001",
},
];
msw.use(
http.get(
"*/accounts/:accountId/r2/buckets",
async ({ request, params }) => {
const { accountId } = params;
expect(accountId).toEqual("some-account-id");
expect(await request.text()).toEqual("");
return HttpResponse.json(
createFetchResult({
buckets: mockBuckets,
})
);
},
{ once: true }
)
);

await runWrangler(`r2 bucket list`);
expect(std.out).toMatchInlineSnapshot(`
"
⛅️ wrangler x.x.x
──────────────────
Listing buckets...
name: bucket-1-local-once
creation_date: 01-01-2001

name: bucket-2-local-once
creation_date: 01-01-2001"
`);
});
});

describe("info", () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/wrangler/src/r2/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ export const r2BucketListCommand = createCommand({
status: "stable",
owner: "Product: R2",
},
behaviour: {
// This is an account-level command and does not require a valid project config.
// Keeping config parsing out of the critical path avoids blocking users who are
// using `wrangler r2 bucket list` to debug/fix an invalid wrangler.jsonc/toml.
provideConfig: false,
},
args: {
jurisdiction: {
describe: "The jurisdiction to list",
Expand Down
Loading