Skip to content

[wrangler] Fix first-deploy guidance for required secrets#14332

Open
Divkix wants to merge 2 commits into
cloudflare:mainfrom
Divkix:fix/issue-14258-required-secrets-first-deploy-guidance
Open

[wrangler] Fix first-deploy guidance for required secrets#14332
Divkix wants to merge 2 commits into
cloudflare:mainfrom
Divkix:fix/issue-14258-required-secrets-first-deploy-guidance

Conversation

@Divkix

@Divkix Divkix commented Jun 17, 2026

Copy link
Copy Markdown

Fixes #14258.

On a first deploy of a new Worker that declares secrets: { required: [...] }, every remedy Wrangler suggested was impossible:

  • wrangler secret put <NAME> → fails, the Worker doesn't exist yet (API 10007)
  • .dev.vars / .envwrangler deploy doesn't read these
  • The one working path — wrangler deploy --secrets-file <file> — was mentioned nowhere.

This PR fixes the guidance so it points at the path that actually works:

  • Pre-deploy error (addRequiredSecretsInheritBindings, first-deploy branch): now explains that wrangler secret put can't be used for a Worker that doesn't exist yet, and directs users to wrangler deploy --secrets-file <path-to-file> (with the expected SECRET_NAME=value/JSON file format).
  • Post-deploy API error (handleMissingSecretsError, code 10057): now also surfaces the --secrets-file option alongside secret put, branching the recommended command per code path (wrangler deploy --secrets-file vs wrangler versions upload --secrets-file).

This is the low-risk messaging fix. The issue also proposes a deeper behavioral change (routing env/.dev.vars-supplied required secrets through the "new secret binding" path that --secrets-file uses, instead of the inherit path that yields 10057 on first deploy). I assessed that as a separate, more invasive feature: there is currently no code path that reads process.env/.dev.vars into secret bindings at deploy time, so this would be net-new behavior rather than a re-route. Left as a follow-up.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this only updates Wrangler's CLI error message copy; no public documentation describes these specific error strings.

A picture of a cute animal (not mandatory, but encouraged)

🦦


Open in Devin Review

When deploying a new Worker that declares secrets.required, the previous
error suggested `wrangler secret put` (fails with 10007 for a Worker that
does not exist yet) and .dev.vars/env (not read by deploy). The one working
path, `wrangler deploy --secrets-file`, was never mentioned.

The pre-deploy error now directs users to --secrets-file, and the post-deploy
10057 error mentions it too, branching the command per code path (deploy vs
versions upload).
@Divkix Divkix requested a review from workers-devprod as a code owner June 17, 2026 08:15
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 460f500

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

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@workers-devprod workers-devprod requested review from a team and NuroDev and removed request for a team June 17, 2026 08:16
@workers-devprod

workers-devprod commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

Comment on lines +74 to +81
const secretPutCommand =
options.type === "deploy"
? "wrangler secret put"
: "wrangler versions secret put";
const secretsFileCommand =
options.type === "deploy"
? "wrangler deploy --secrets-file <path-to-file>"
: "wrangler versions upload --secrets-file <path-to-file>";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could could probably be streamlined into a template string. For example:

const secretPutCommand = `wrangler ${options.type === "deploy" ? "versions" : ""}secret put`;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done in 460f500. Also, heads up as the example had the branches flipped for our logic (deploy is plain secret put, upload is versions secret put), so I kept that order:

const secretPutCommand = `wrangler ${options.type === "deploy" ? "" : "versions "}secret put`;

Did the same for secretsFileCommand while I was at it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good catch! Thanks!

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jun 17, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown
create-cloudflare

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

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@14332

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@14332

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 9cf2067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

3 participants