Skip to content

Commit ece449e

Browse files
committed
cloudchamber: capitalize every event message
1 parent 080ef13 commit ece449e

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

.changeset/tricky-schools-heal.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Event messages are capitalized, images of wrong architectures properly show the error in `cloudchamber create`
6+
When a new "health" enum is introduced, `wrangler cloudchamber list` won't crash anymore.
7+
Update Cloudchamber schemas.

packages/wrangler/src/__tests__/helpers/mock-cloudchamber.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { DeploymentType, NodeGroup } from "../../cloudchamber/client";
1+
import {
2+
DeploymentType,
3+
NodeGroup,
4+
PlacementStatusHealth,
5+
} from "../../cloudchamber/client";
26
import type {
37
DeploymentV2,
48
PlacementWithEvents,
@@ -42,7 +46,7 @@ export const MOCK_DEPLOYMENTS: DeploymentV2[] = [
4246
},
4347
current_placement: {
4448
deployment_version: 2,
45-
status: { health: "running" },
49+
status: { health: PlacementStatusHealth.RUNNING },
4650
deployment_id: "2",
4751
terminate: false,
4852
created_at: "123",
@@ -91,7 +95,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
9195
},
9296
current_placement: {
9397
deployment_version: 2,
94-
status: { health: "running" },
98+
status: { health: PlacementStatusHealth.RUNNING },
9599
deployment_id: "2",
96100
terminate: false,
97101
created_at: "123",
@@ -137,7 +141,7 @@ export const MOCK_DEPLOYMENTS_COMPLEX: DeploymentV2[] = [
137141
},
138142
current_placement: {
139143
deployment_version: 2,
140-
status: { health: "running" },
144+
status: { health: PlacementStatusHealth.RUNNING },
141145
deployment_id: "2",
142146
terminate: false,
143147
created_at: "123",
@@ -156,7 +160,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
156160
deployment_version: 2,
157161
terminate: false,
158162
events: [],
159-
status: { health: "stopped" },
163+
status: { health: PlacementStatusHealth.STOPPED },
160164
},
161165
{
162166
id: "3",
@@ -165,7 +169,7 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
165169
deployment_version: 3,
166170
terminate: false,
167171
events: [],
168-
status: { health: "failed" },
172+
status: { health: PlacementStatusHealth.FAILED },
169173
},
170174
{
171175
id: "1",
@@ -174,6 +178,6 @@ export const MOCK_PLACEMENTS: PlacementWithEvents[] = [
174178
deployment_version: 4,
175179
terminate: false,
176180
events: [],
177-
status: { health: "running" },
181+
status: { health: PlacementStatusHealth.RUNNING },
178182
},
179183
];

packages/wrangler/src/cloudchamber/cli/index.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "../client";
1717
import { wrap } from "../helpers/wrap";
1818
import { idToLocationName } from "../locations";
19+
import { capitalize } from "./util";
1920
import type {
2021
CustomerImageRegistry,
2122
DeploymentV2,
@@ -213,7 +214,6 @@ async function waitForImagePull(deployment: DeploymentV2) {
213214
s.stop();
214215
if (err) {
215216
crash(err.message);
216-
return;
217217
}
218218

219219
if (
@@ -226,13 +226,19 @@ async function waitForImagePull(deployment: DeploymentV2) {
226226
}
227227

228228
if (eventPlacement.event.name == "ImagePullError") {
229-
crash(
230-
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
231-
`Run ${brandColor(
232-
process.argv0 + " cloudchamber modify " + deployment.id
233-
)} to change the deployment image`
234-
);
235-
return;
229+
// TODO: We should really report here something more specific when it's not found.
230+
// For now, the cloudchamber API always returns a 404 in the message when the
231+
// image is not found.
232+
if (eventPlacement.event.message.includes("404")) {
233+
crash(
234+
"Your container image couldn't be pulled, (404 not found). Did you specify the correct URL?",
235+
`Run ${brandColor(
236+
process.argv0 + " cloudchamber modify " + deployment.id
237+
)} to change the deployment image`
238+
);
239+
}
240+
241+
crash(capitalize(eventPlacement.event.message));
236242
}
237243

238244
updateStatus("Pulled your image");
@@ -265,7 +271,6 @@ async function waitForVMToStart(deployment: DeploymentV2) {
265271
s.stop();
266272
if (err) {
267273
crash(err.message);
268-
return;
269274
}
270275

271276
if (!eventPlacement.event) {
@@ -326,7 +331,6 @@ async function waitForPlacementInstance(deployment: DeploymentV2) {
326331

327332
if (err) {
328333
crash(err.message);
329-
return;
330334
}
331335

332336
updateStatus(

packages/wrangler/src/cloudchamber/cli/util.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { bgGreen, bgRed, bgYellow } from "@cloudflare/cli/colors";
2-
import { PlacementStatusHealth } from "../client";
2+
import { type PlacementStatusHealth } from "../client";
3+
4+
export function capitalize<S extends string>(str: S): Capitalize<S> {
5+
return (
6+
str.length > 0 ? str[0].toUpperCase() + str.substring(1) : str
7+
) as Capitalize<S>;
8+
}
39

410
export function statusToColored(status?: PlacementStatusHealth): string {
511
if (!status) {

packages/wrangler/src/cloudchamber/list.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { inputPrompt, spinner } from "@cloudflare/cli/interactive";
1313
import isInteractive from "../is-interactive";
1414
import { listDeploymentsAndChoose, loadDeployments } from "./cli/deployments";
15-
import { statusToColored } from "./cli/util";
15+
import { capitalize, statusToColored } from "./cli/util";
1616
import { DeploymentsService, PlacementsService } from "./client";
1717
import { loadAccountSpinner, promiseSpinner } from "./common";
1818
import type { Config } from "../config";
@@ -115,6 +115,7 @@ export async function listCommand(
115115
*/
116116
function eventMessage(event: PlacementEvent, lastEvent: boolean): string {
117117
let { message } = event;
118+
message = capitalize(message);
118119
const name = event.name as EventName;
119120
const health = event.statusChange["health"];
120121
if (health === "failed") {

0 commit comments

Comments
 (0)