Skip to content

Commit

Permalink
wrangler cloudchamber: fix --json flags when required fields for it t…
Browse files Browse the repository at this point in the history
…o work are not passed
  • Loading branch information
gabivlj authored and IRCody committed Jul 12, 2024
1 parent 8bbd824 commit abef5a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-eyes-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: wrangler cloudchamber json errors are properly formatted
60 changes: 40 additions & 20 deletions packages/wrangler/src/__tests__/cloudchamber/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ describe("cloudchamber create", () => {
`);
});

it("should fail with a nice message when parameters are missing", async () => {
setIsTTY(false);
setWranglerConfig({});
await expect(
runWrangler("cloudchamber create --image hello:world")
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: location is required but it's not passed as an argument]`
);
});

it("should fail with a nice message when parameters are missing (json)", async () => {
setIsTTY(false);
setWranglerConfig({});
await runWrangler("cloudchamber create --image hello:world --json");
expect(std.out).toMatchInlineSnapshot(
`"{\\"error\\":\\"location is required but it's not passed as an argument\\"}"`
);
expect(std.err).toMatchInlineSnapshot(`""`);
});

it("should create deployment (detects no interactivity)", async () => {
setIsTTY(false);
setWranglerConfig({});
Expand Down Expand Up @@ -86,26 +106,26 @@ describe("cloudchamber create", () => {
// so testing the actual UI will be harder than expected
// TODO: think better on how to test UI actions
expect(std.out).toMatchInlineSnapshot(`
"{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`);
"{
\\"id\\": \\"1\\",
\\"type\\": \\"default\\",
\\"created_at\\": \\"123\\",
\\"account_id\\": \\"123\\",
\\"vcpu\\": 4,
\\"memory\\": \\"400MB\\",
\\"version\\": 1,
\\"image\\": \\"hello\\",
\\"location\\": {
\\"name\\": \\"sfo06\\",
\\"enabled\\": true
},
\\"network\\": {
\\"ipv4\\": \\"1.1.1.1\\"
},
\\"placements_ref\\": \\"http://ref\\",
\\"node_group\\": \\"metal\\"
}"
`);
});

it("should create deployment indicating ssh keys (detects no interactivity)", async () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/wrangler/src/cloudchamber/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export function handleFailure<
}

if (err instanceof Error) {
logger.log(
`${{ error: err.message, name: err.name, stack: err.stack }}`
);
logger.log(`${JSON.stringify({ error: err.message })}`);
return;
}

Expand Down

0 comments on commit abef5a4

Please sign in to comment.