[wrangler] Fix first-deploy guidance for required secrets#14332
Conversation
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).
🦋 Changeset detectedLatest commit: 460f500 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 |
| 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>"; |
There was a problem hiding this comment.
These could could probably be streamlined into a template string. For example:
const secretPutCommand = `wrangler ${options.type === "deploy" ? "versions" : ""}secret put`;There was a problem hiding this comment.
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.
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
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 (API10007).dev.vars/.env→wrangler deploydoesn't read thesewrangler deploy --secrets-file <file>— was mentioned nowhere.This PR fixes the guidance so it points at the path that actually works:
addRequiredSecretsInheritBindings, first-deploy branch): now explains thatwrangler secret putcan't be used for a Worker that doesn't exist yet, and directs users towrangler deploy --secrets-file <path-to-file>(with the expectedSECRET_NAME=value/JSON file format).handleMissingSecretsError, code10057): now also surfaces the--secrets-fileoption alongsidesecret put, branching the recommended command per code path (wrangler deploy --secrets-filevswrangler 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-fileuses, instead of the inherit path that yields10057on first deploy). I assessed that as a separate, more invasive feature: there is currently no code path that readsprocess.env/.dev.varsinto secret bindings at deploy time, so this would be net-new behavior rather than a re-route. Left as a follow-up.A picture of a cute animal (not mandatory, but encouraged)
🦦