Skip to content

Conversation

@ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Dec 17, 2025

Fixes #9358.

When a 401 authentication error occurs, this PR adds a warning if the account_id in the Wrangler configuration does not match any of the user's authenticated accounts. This helps users identify configuration issues where they may have copied an account_id from another account or project.

The warning is displayed after the account list in the whoami output that appears on authentication errors, making it clear that the configured account ID is not accessible with the current credentials.

Key changes:

  • Added printAccountIdMismatchWarning function in whoami.ts that checks if the configured account_id matches any authenticated accounts
  • Modified handleError to extract account_id from config and pass it to whoami
  • Added unit tests for the warning logic

Human review checklist:

  • Verify the warning conditions are correct (warning only shows when accountFilter === configAccountId AND account is not in user's accounts)
  • Verify the warning message is clear and actionable for users

Link to Devin run: https://app.devin.ai/sessions/d7fdc064c9914225b7de6694b36e0122
Devin PR requested by @ascorbic

… error

When a 401 authentication error occurs, display a warning if the account_id
in the Wrangler configuration does not match any of the user's authenticated
accounts. This helps users identify configuration issues where they may have
the wrong account ID set in their wrangler.toml file.

Fixes #9358

Co-Authored-By: [email protected] <[email protected]>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@changeset-bot
Copy link

changeset-bot bot commented Dec 17, 2025

🦋 Changeset detected

Latest commit: 7c3ed78

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link
Contributor

claude bot commented Dec 17, 2025

Claude finished @ascorbic's task —— View job


Changeset Review Complete

  • Read changeset guidelines from .changeset/README.md
  • Read the changeset file in this PR
  • Validate version type
  • Validate changelog quality
  • Check for forbidden markdown headers
  • Provide final assessment

All changesets look good

The changeset .changeset/account-id-mismatch-warning.md passes all validation criteria:

  • ✅ Correct version type: patch (appropriate for a UX improvement/warning message)
  • ✅ No major version (which is forbidden for wrangler)
  • ✅ Clear, meaningful description explaining the symptom and how it helps users
  • ✅ No forbidden h1/h2/h3 markdown headers
  • ✅ Mentions both wrangler.toml and wrangler.jsonc configuration files

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11683

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11683

miniflare

npm i https://pkg.pr.new/miniflare@11683

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11683

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11683

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11683

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11683

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11683

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11683

wrangler

npm i https://pkg.pr.new/wrangler@11683

commit: 7c3ed78

devin-ai-integration bot added a commit that referenced this pull request Dec 17, 2025
…error (v3 backport)

Backport of #11683 to v3-maintenance branch.

When a 401 authentication error occurs, display a warning if the account_id
in the Wrangler configuration does not match any of the user's authenticated
accounts. This helps users identify configuration issues where they may have
the wrong account ID set in their wrangler.toml file.

Fixes #9358

Co-Authored-By: [email protected] <[email protected]>
devin-ai-integration bot and others added 2 commits December 17, 2025 17:10
Move the default value assignment to the variable declaration instead of
the catch block. This is a minor simplification as the full optional
chaining approach doesn't work due to type constraints - ComplianceConfig
doesn't include account_id, only the full Config type does.

Co-Authored-By: [email protected] <[email protected]>
@ascorbic ascorbic marked this pull request as ready for review December 17, 2025 17:27
@ascorbic ascorbic requested a review from a team as a code owner December 17, 2025 17:27
@ascorbic
Copy link
Contributor Author

(aside) I've reviewed this and it looks good.

@github-actions
Copy link
Contributor

Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the v3-maintenance branch with your changes. Thank you for helping us keep Wrangler v3 supported!

Depending on your changes, running git rebase --onto v3-maintenance main devin/1765967113-account-id-mismatch-warning might be a good starting point.

Notes:

  • your PR branch should be named v3-backport-11683
  • add the skip-v3-pr label to the current PR to stop this workflow from failing

- Update changeset to mention both wrangler.toml and wrangler.jsonc
- Convert inline comment to JSDoc for printAccountIdMismatchWarning function

Co-Authored-By: [email protected] <[email protected]>
Address vicb's review feedback to add JSDoc documentation.

Co-Authored-By: [email protected] <[email protected]>
@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Dec 18, 2025
@ascorbic ascorbic merged commit 02fbd22 into main Dec 18, 2025
36 of 38 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 18, 2025
@ascorbic ascorbic deleted the devin/1765967113-account-id-mismatch-warning branch December 18, 2025 16:56
dario-piotrowicz pushed a commit that referenced this pull request Dec 19, 2025
… error (#11683)

* feat(wrangler): add warning when account_id mismatch detected on auth error

When a 401 authentication error occurs, display a warning if the account_id
in the Wrangler configuration does not match any of the user's authenticated
accounts. This helps users identify configuration issues where they may have
the wrong account ID set in their wrangler.toml file.

Fixes #9358

Co-Authored-By: [email protected] <[email protected]>

* refactor: simplify complianceConfig initialization

Move the default value assignment to the variable declaration instead of
the catch block. This is a minor simplification as the full optional
chaining approach doesn't work due to type constraints - ComplianceConfig
doesn't include account_id, only the full Config type does.

Co-Authored-By: [email protected] <[email protected]>

* chore: address review feedback

- Update changeset to mention both wrangler.toml and wrangler.jsonc
- Convert inline comment to JSDoc for printAccountIdMismatchWarning function

Co-Authored-By: [email protected] <[email protected]>

* chore: add JSDoc to whoami function

Address vicb's review feedback to add JSDoc documentation.

Co-Authored-By: [email protected] <[email protected]>

* Minor `whoami` JSDoc tweaks

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Ben <[email protected]>
edmundhung pushed a commit that referenced this pull request Dec 19, 2025
…error (v3 backport) (#11689)

* fix(wrangler): add warning when account_id mismatch detected on auth error (v3 backport)

Backport of #11683 to v3-maintenance branch.

When a 401 authentication error occurs, display a warning if the account_id
in the Wrangler configuration does not match any of the user's authenticated
accounts. This helps users identify configuration issues where they may have
the wrong account ID set in their wrangler.toml file.

Fixes #9358

Co-Authored-By: [email protected] <[email protected]>

* fix: capture configAccountId in middleware instead of catch block

Move the config reading to the middleware callback where args is in scope,
and capture configAccountId there. This fixes the TypeScript error where
args was not defined in the catch block.

Co-Authored-By: [email protected] <[email protected]>

* style: fix formatting in whoami files

Co-Authored-By: [email protected] <[email protected]>

* chore: address review feedback - add JSDoc comments

- Add JSDoc to whoami function
- Add JSDoc to printAccountIdMismatchWarning function
- Update changeset to mention wrangler.jsonc

Co-Authored-By: [email protected] <[email protected]>

* chore: add backticks to JSDoc parameter names

Address NuroDev's review feedback to add backticks around parameter names in JSDoc comments.

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
AmirSa12 pushed a commit to AmirSa12/workers-sdk that referenced this pull request Jan 5, 2026
… error (cloudflare#11683)

* feat(wrangler): add warning when account_id mismatch detected on auth error

When a 401 authentication error occurs, display a warning if the account_id
in the Wrangler configuration does not match any of the user's authenticated
accounts. This helps users identify configuration issues where they may have
the wrong account ID set in their wrangler.toml file.

Fixes cloudflare#9358

Co-Authored-By: [email protected] <[email protected]>

* refactor: simplify complianceConfig initialization

Move the default value assignment to the variable declaration instead of
the catch block. This is a minor simplification as the full optional
chaining approach doesn't work due to type constraints - ComplianceConfig
doesn't include account_id, only the full Config type does.

Co-Authored-By: [email protected] <[email protected]>

* chore: address review feedback

- Update changeset to mention both wrangler.toml and wrangler.jsonc
- Convert inline comment to JSDoc for printAccountIdMismatchWarning function

Co-Authored-By: [email protected] <[email protected]>

* chore: add JSDoc to whoami function

Address vicb's review feedback to add JSDoc documentation.

Co-Authored-By: [email protected] <[email protected]>

* Minor `whoami` JSDoc tweaks

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Ben <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

FEATURE(wrangler): display details when a CLI 401 an account_id is specified in the wrangler config

3 participants