Skip to content

Commit e7c06d7

Browse files
authored
wrangler cloudchamber: fix --json flags when required fields for it to work are not passed (#6244)
1 parent eba40d0 commit e7c06d7

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

.changeset/nervous-eyes-fetch.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+
fix: wrangler cloudchamber json errors are properly formatted

packages/wrangler/src/__tests__/cloudchamber/create.test.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ describe("cloudchamber create", () => {
5252
`);
5353
});
5454

55+
it("should fail with a nice message when parameters are missing", async () => {
56+
setIsTTY(false);
57+
setWranglerConfig({});
58+
await expect(
59+
runWrangler("cloudchamber create --image hello:world")
60+
).rejects.toThrowErrorMatchingInlineSnapshot(
61+
`[Error: location is required but it's not passed as an argument]`
62+
);
63+
});
64+
65+
it("should fail with a nice message when parameters are missing (json)", async () => {
66+
setIsTTY(false);
67+
setWranglerConfig({});
68+
await runWrangler("cloudchamber create --image hello:world --json");
69+
expect(std.out).toMatchInlineSnapshot(
70+
`"{\\"error\\":\\"location is required but it's not passed as an argument\\"}"`
71+
);
72+
expect(std.err).toMatchInlineSnapshot(`""`);
73+
});
74+
5575
it("should create deployment (detects no interactivity)", async () => {
5676
setIsTTY(false);
5777
setWranglerConfig({});
@@ -86,26 +106,26 @@ describe("cloudchamber create", () => {
86106
// so testing the actual UI will be harder than expected
87107
// TODO: think better on how to test UI actions
88108
expect(std.out).toMatchInlineSnapshot(`
89-
"{
90-
\\"id\\": \\"1\\",
91-
\\"type\\": \\"default\\",
92-
\\"created_at\\": \\"123\\",
93-
\\"account_id\\": \\"123\\",
94-
\\"vcpu\\": 4,
95-
\\"memory\\": \\"400MB\\",
96-
\\"version\\": 1,
97-
\\"image\\": \\"hello\\",
98-
\\"location\\": {
99-
\\"name\\": \\"sfo06\\",
100-
\\"enabled\\": true
101-
},
102-
\\"network\\": {
103-
\\"ipv4\\": \\"1.1.1.1\\"
104-
},
105-
\\"placements_ref\\": \\"http://ref\\",
106-
\\"node_group\\": \\"metal\\"
107-
}"
108-
`);
109+
"{
110+
\\"id\\": \\"1\\",
111+
\\"type\\": \\"default\\",
112+
\\"created_at\\": \\"123\\",
113+
\\"account_id\\": \\"123\\",
114+
\\"vcpu\\": 4,
115+
\\"memory\\": \\"400MB\\",
116+
\\"version\\": 1,
117+
\\"image\\": \\"hello\\",
118+
\\"location\\": {
119+
\\"name\\": \\"sfo06\\",
120+
\\"enabled\\": true
121+
},
122+
\\"network\\": {
123+
\\"ipv4\\": \\"1.1.1.1\\"
124+
},
125+
\\"placements_ref\\": \\"http://ref\\",
126+
\\"node_group\\": \\"metal\\"
127+
}"
128+
`);
109129
});
110130

111131
it("should create deployment indicating ssh keys (detects no interactivity)", async () => {

packages/wrangler/src/cloudchamber/common.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export function handleFailure<
7979
}
8080

8181
if (err instanceof Error) {
82-
logger.log(
83-
`${{ error: err.message, name: err.name, stack: err.stack }}`
84-
);
82+
logger.log(`${JSON.stringify({ error: err.message })}`);
8583
return;
8684
}
8785

0 commit comments

Comments
 (0)