[wrangler] fix: show env-var hint when /memberships returns code 9106 (bad credentials)#13839
[wrangler] fix: show env-var hint when /memberships returns code 9106 (bad credentials)#13839matingathani wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: b8e3f6b The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
There was a problem hiding this comment.
Pull request overview
Improves Wrangler’s handling of Cloudflare API /memberships failures by recognizing error code 9106 (“Missing X-Auth-Key, X-Auth-Email or Authorization headers”) as a bad-credentials scenario and surfacing an actionable UserError that points users to relevant credential environment variables and re-auth steps.
Changes:
- Add a
/memberships“bad credentials” code list (9106) and helper to detect it. - Throw a targeted
UserErrorwith env-var guidance and suggestedwrangler logout/wrangler loginsteps when 9106 occurs. - Add a regression test asserting the improved hint is shown, plus a changeset entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/wrangler/src/user/fetch-accounts.ts |
Detect 9106 as bad credentials and throw a more actionable UserError. |
packages/wrangler/src/__tests__/user.test.ts |
Add coverage ensuring the new env-var hint appears for 9106 from /memberships. |
.changeset/fix-auth-error-hint-env-var.md |
Publish a patch changeset describing the improved error messaging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@NuroDev @penalosa @dario-piotrowicz — all Copilot review comments have been addressed. This PR is ready for review. |
c9a4e7d to
671ef7e
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
The CI failures in job 75276344917 are in Miniflare's browser plugin test suite ( |
dario-piotrowicz
left a comment
There was a problem hiding this comment.
Thanks for the PR @matingathani 🙂
The PR generally looks good to me, I just left a few small comments
Also the browser test keeps failing, could you maybe try rebasing the PR and see if that helps? 🙂
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
…edentials)
When the Cloudflare API returns code 9106 ("Missing X-Auth-Key, X-Auth-Email
or Authorization headers"), Wrangler now emits a UserError explaining that
an environment variable such as CLOUDFLARE_API_TOKEN may be set to an invalid
value, and suggests running `wrangler logout` / `wrangler login` to re-authenticate.
Previously the raw API error was rethrown with no guidance, leaving users
confused about why their credentials were rejected.
Fixes cloudflare#13656
… use it in isMembershipsInaccessible, remove "also" from comment
04f419c to
b8e3f6b
Compare
|
New CI failure (Tests, macOS, fixtures) is in |
Fixes #13656.
When
/membershipsreturns error code 9106 ("Authentication failed") and/accountsis also empty (no usable accounts), Wrangler previously showed a generic "incorrect permissions" message. This PR surfaces a more actionable hint that an environment variable likeCLOUDFLARE_API_TOKENmay be set to an invalid value.Context: PR #13858 added 9106 to
MEMBERSHIPS_INACCESSIBLE_CODES— a valid Account API Token returns 9106 on/membershipssince that endpoint is user-level. When/accountshas data, the existing fallback works correctly. This PR handles the edge case where 9106 is returned AND/accountsis also empty, which can happen when an env-var credential is malformed.Change: Inside the
isMembershipsInaccessibleblock, when code is specifically 9106 and no accounts are available, throw aUserErrorthat names the env-var candidates (CLOUDFLARE_API_TOKEN,CLOUDFLARE_API_KEY,CLOUDFLARE_EMAIL) and suggestswrangler logout && wrangler login.