Skip to content

Commit 09464a6

Browse files
Improve error message displayed when a redirected config includes multiple environments (#8809)
* update wrong test `it` text * improve error message when redirected config contains environments * combine tests
1 parent 120f6c6 commit 09464a6

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

.changeset/silent-keys-bake.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
improve error message when redirected config contains environments
6+
7+
this change improves that validation error message that users see
8+
when a redirected config file contains environments, by:
9+
10+
- cleaning the message formatting and displaying the
11+
offending environments in a list
12+
- prompting the user to report the issue to the author
13+
of the tool which has generated the config

fixtures/redirected-config-worker-with-environments/tests/index.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";
44

55
const basePath = resolve(__dirname, "..");
66

7-
describe("'wrangler dev' errors because redirected configs can't include environments", () => {
8-
it("uses the generated config", async ({ expect }) => {
9-
await expect(
10-
runWranglerDev(basePath, ["--port=0", "--inspector-port=0"])
11-
).rejects.toThrowError(
12-
/Redirected configurations cannot include environments but the following have been found: \"staging\"/
7+
describe("'wrangler dev' errors when a redirected config includes environments", () => {
8+
it("A clear error message is presented which includes the offending environments and prompting the user to contact the tool's author", async ({
9+
expect,
10+
}) => {
11+
let error: string | undefined;
12+
try {
13+
await runWranglerDev(basePath, ["--port=0", "--inspector-port=0"]);
14+
} catch (e) {
15+
if (typeof e === "string") {
16+
error = e;
17+
}
18+
}
19+
expect(error).toBeTruthy();
20+
expect(error).toMatch(
21+
/Redirected configurations cannot include environments but the following have been found:/
1322
);
23+
expect(error).toContain("staging");
24+
expect(error).toContain("testing");
25+
26+
expect(error).toContain("Report this issue to the tool's author");
1427
});
1528
});

fixtures/redirected-config-worker-with-environments/tools/build.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ const config = {
1515
environmentName: "staging",
1616
},
1717
},
18+
testing: {
19+
vars: {
20+
generated: true,
21+
environmentName: "testing",
22+
},
23+
},
1824
},
1925
};
2026
writeFileSync("build/wrangler.json", JSON.stringify(config, undefined, 2));

fixtures/redirected-config-worker/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("'wrangler dev' correctly renders pages", () => {
2020
expect(text).toMatchInlineSnapshot(`"Generated: true"`);
2121
});
2222

23-
it("specifying an environment cause an error since they are supported in redirected configs", async ({
23+
it("specifying an environment causes an error since they are not supported in redirected configs", async ({
2424
expect,
2525
}) => {
2626
await expect(

packages/wrangler/src/config/validation.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ export function normalizeAndValidateConfig(
161161

162162
if (isRedirectedConfig && definedEnvironments.length > 0) {
163163
diagnostics.errors.push(
164-
`Redirected configurations cannot include environments but the following have been found: ${definedEnvironments.map((env) => JSON.stringify(env)).join(", ")}`
164+
dedent`
165+
Redirected configurations cannot include environments but the following have been found:\n${definedEnvironments
166+
.map((env) => ` - ${env}`)
167+
.join("\n")}
168+
169+
170+
Such configurations are generated by tools, meaning that one of the tools
171+
your application is using is generating the incorrect configuration.
172+
Report this issue to the tool's author so that this can be fixed there.
173+
`
165174
);
166175
}
167176

0 commit comments

Comments
 (0)