Skip to content

Commit 695b043

Browse files
authored
Improve 'wrangler secret put' error message when using Worker versions (#11882)
1 parent fec8f5b commit 695b043

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

.changeset/ten-pants-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Improve the error message for `wrangler secret put` when using Worker versions or gradual deployments. `wrangler versions secret put` should be used instead, or ensure to deploy the latest version before using `wrangler secret put`. `wrangler secret put` alone will add the new secret to the latest version (possibly undeployed) and immediately deploy that which is usually not intended.

packages/wrangler/src/__tests__/secret.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,12 @@ describe("wrangler secret", () => {
547547

548548
await expect(runWrangler(`secret put secret-name --name ${scriptName}`))
549549
.rejects.toThrowErrorMatchingInlineSnapshot(`
550-
[Error: Secret edit failed. You attempted to modify a secret, but the latest version of your Worker isn't currently deployed. Please ensure that the latest version of your Worker is fully deployed (wrangler versions deploy) before modifying secrets. Alternatively, you can use the Cloudflare dashboard to modify secrets and deploy the version.
551-
552-
Note: This limitation will be addressed in an upcoming release.]
550+
[Error: Secret edit failed. You attempted to modify a secret, but the latest version of your Worker isn't currently deployed.
551+
This limitation exists to prevent accidental deployment when using Worker versions and secrets together.
552+
To resolve this, you have two options:
553+
(1) use the \`wrangler versions secret put\` instead, which allows you to update secrets without deploying; or
554+
(2) deploy the latest version first, then modify secrets.
555+
Alternatively, you can use the Cloudflare dashboard to modify secrets and deploy the version.]
553556
`);
554557
});
555558
});

packages/wrangler/src/secret/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,12 @@ export const secretPutCommand = createCommand({
216216
} catch (e) {
217217
if (e instanceof APIError && e.code === VERSION_NOT_DEPLOYED_ERR_CODE) {
218218
throw new UserError(
219-
"Secret edit failed. You attempted to modify a secret, but the latest version of your Worker isn't currently deployed. " +
220-
"Please ensure that the latest version of your Worker is fully deployed " +
221-
"(wrangler versions deploy) before modifying secrets. " +
222-
"Alternatively, you can use the Cloudflare dashboard to modify secrets and deploy the version." +
223-
"\n\nNote: This limitation will be addressed in an upcoming release."
219+
"Secret edit failed. You attempted to modify a secret, but the latest version of your Worker isn't currently deployed.\n" +
220+
"This limitation exists to prevent accidental deployment when using Worker versions and secrets together.\n" +
221+
"To resolve this, you have two options:\n" +
222+
"(1) use the `wrangler versions secret put` instead, which allows you to update secrets without deploying; or\n" +
223+
"(2) deploy the latest version first, then modify secrets.\n" +
224+
"Alternatively, you can use the Cloudflare dashboard to modify secrets and deploy the version."
224225
);
225226
} else {
226227
throw e;

0 commit comments

Comments
 (0)