Skip to content

Commit ecbe026

Browse files
authored
Provide more informative error messages for Workers CI tag validation (#8625)
1 parent d611caf commit ecbe026

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

packages/wrangler/src/__tests__/match-tag.test.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ describe("match-tag", () => {
4444
);
4545
} else if (params.workerName === "network-error-worker") {
4646
return HttpResponse.error();
47+
} else if (params.workerName === "auth-error-worker") {
48+
return HttpResponse.json(
49+
{
50+
success: false,
51+
errors: [
52+
{
53+
code: 10000,
54+
message: "Authentication error",
55+
},
56+
],
57+
},
58+
{ status: 401 }
59+
);
4760
} else {
4861
return HttpResponse.json(
4962
{
@@ -92,13 +105,27 @@ describe("match-tag", () => {
92105
);
93106
});
94107

95-
it("catches all other API errors and throws generic validation error", async () => {
108+
it("catches all other API errors and throws proper error", async () => {
109+
vi.stubEnv("WRANGLER_CI_MATCH_TAG", "abc123");
110+
mockWorker("a-worker", "abc123");
111+
await expect(
112+
verifyWorkerMatchesCITag("some-account-id", "auth-error-worker")
113+
).rejects.toMatchInlineSnapshot(
114+
`
115+
[Error: An error occurred while trying to validate that the Worker name matches what is expected by the build system.
116+
A request to the Cloudflare API (/accounts/some-account-id/workers/services/auth-error-worker) failed.
117+
Authentication error [code: 10000]]
118+
`
119+
);
120+
});
121+
122+
it("catches all other errors and throws generic error", async () => {
96123
vi.stubEnv("WRANGLER_CI_MATCH_TAG", "abc123");
97124
mockWorker("a-worker", "abc123");
98125
await expect(
99126
verifyWorkerMatchesCITag("some-account-id", "network-error-worker")
100127
).rejects.toMatchInlineSnapshot(
101-
`[Error: Wrangler cannot validate that your Worker name matches what is expected by the build system. Please retry the build.]`
128+
`[Error: Wrangler cannot validate that your Worker name matches what is expected by the build system. Please retry the build. If the problem persists, please contact support.]`
102129
);
103130
});
104131

@@ -143,11 +170,15 @@ describe("match-tag", () => {
143170
it("catches all other API errors and throws generic validation error", async () => {
144171
vi.stubEnv("WRANGLER_CI_MATCH_TAG", "abc123");
145172
mockWorker("a-worker", "abc123");
146-
writeWranglerConfig({ name: "network-error-worker" });
173+
writeWranglerConfig({ name: "auth-error-worker" });
147174
await expect(
148175
runWrangler("deploy ./index.js")
149176
).rejects.toMatchInlineSnapshot(
150-
`[Error: Wrangler cannot validate that your Worker name matches what is expected by the build system. Please retry the build.]`
177+
`
178+
[Error: An error occurred while trying to validate that the Worker name matches what is expected by the build system.
179+
A request to the Cloudflare API (/accounts/some-account-id/workers/services/auth-error-worker) failed.
180+
Authentication error [code: 10000]]
181+
`
151182
);
152183
});
153184

packages/wrangler/src/environment-variables/misc-variables.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ export const getOutputFilePathFromEnv = getEnvironmentVariableFactory({
9393
});
9494

9595
/**
96-
* `WRANGLER_CI_MATCH_TAG` specifies a worker tag
96+
* `WRANGLER_CI_MATCH_TAG` specifies a Worker tag
9797
*
98-
* If this is set, Wrangler will ensure the worker being targeted has this tag
98+
* If this is set, Wrangler will ensure the Worker being targeted has this tag
9999
*/
100100
export const getCIMatchTag = getEnvironmentVariableFactory({
101101
variableName: "WRANGLER_CI_MATCH_TAG",
102102
});
103103

104104
/**
105-
* `WRANGLER_CI_OVERRIDE_TAG` specifies a worker tag
105+
* `WRANGLER_CI_OVERRIDE_NAME` specifies a Worker name
106106
*
107-
* If this is set, Wrangler will override the worker name with this tag
107+
* If this is set, Wrangler will override the Worker name with this one
108108
*/
109109
export const getCIOverrideName = getEnvironmentVariableFactory({
110110
variableName: "WRANGLER_CI_OVERRIDE_NAME",

packages/wrangler/src/match-tag.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { configFileName, formatConfigSnippet } from "./config";
33
import { getCIMatchTag } from "./environment-variables/misc-variables";
44
import { FatalError } from "./errors";
55
import { logger } from "./logger";
6+
import { APIError } from "./parse";
67
import { getCloudflareAccountIdFromEnv } from "./user/auth-variables";
78
import type { ServiceMetadataRes } from "./init";
89

@@ -48,9 +49,17 @@ export async function verifyWorkerMatchesCITag(
4849
throw new FatalError(
4950
`The name in your ${configFileName(configPath)} file (${workerName}) must match the name of your Worker. Please update the name field in your ${configFileName(configPath)} file.`
5051
);
52+
} else if (e instanceof APIError) {
53+
throw new FatalError(
54+
"An error occurred while trying to validate that the Worker name matches what is expected by the build system.\n" +
55+
e.message +
56+
"\n" +
57+
e.notes.map((note) => note.text).join("\n")
58+
);
5159
} else {
5260
throw new FatalError(
53-
"Wrangler cannot validate that your Worker name matches what is expected by the build system. Please retry the build."
61+
"Wrangler cannot validate that your Worker name matches what is expected by the build system. Please retry the build. " +
62+
"If the problem persists, please contact support."
5463
);
5564
}
5665
}

0 commit comments

Comments
 (0)