Skip to content

Commit

Permalink
fix: improve error message when no accounts found during deployment (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot authored Apr 10, 2024
1 parent 4f47f74 commit a13a0c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/large-pumpkins-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-cloudflare": patch
---

fix: display helpful error message when no accounts found during deployment

Previously, C3 would display `TypeError: Cannot read properties of undefined (reading 'value')` if you were logged in as a user without access to any accounts. This change ensures a more appropriate error message is displayed in this case.
7 changes: 6 additions & 1 deletion packages/create-cloudflare/src/wrangler/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const chooseAccount = async (ctx: C3Context) => {

let accountId: string;

if (Object.keys(accounts).length == 1) {
const numAccounts = Object.keys(accounts).length;
if (numAccounts === 0) {
throw new Error(
"Unable to find any accounts to deploy to! Please ensure you're logged in as a user that can deploy Workers."
);
} else if (numAccounts === 1) {
const accountName = Object.keys(accounts)[0];
accountId = accounts[accountName];
s.stop(`${brandColor("account")} ${dim(accountName)}`);
Expand Down

0 comments on commit a13a0c3

Please sign in to comment.