From 8ace61e0eaa66e51aa0d4746f315269f14de46ec Mon Sep 17 00:00:00 2001 From: emily-shen Date: Mon, 11 Aug 2025 15:18:05 +0100 Subject: [PATCH 1/2] format api errors better --- packages/wrangler/src/containers/deploy.ts | 55 ++++++++++------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/wrangler/src/containers/deploy.ts b/packages/wrangler/src/containers/deploy.ts index 1c274828d5..d9126e8c4d 100644 --- a/packages/wrangler/src/containers/deploy.ts +++ b/packages/wrangler/src/containers/deploy.ts @@ -17,7 +17,6 @@ import { ApiError, ApplicationsService, CreateApplicationRolloutRequest, - DeploymentMutationError, resolveImageName, RolloutsService, } from "@cloudflare/containers-shared"; @@ -348,25 +347,21 @@ export async function apply( } function formatError(err: ApiError): string { - // TODO: this is bad bad. Please fix like we do in create.ts. - // On Cloudchamber API side, we have to improve as well the object validation errors, - // so we can detect them here better and pinpoint to the user what's going on. - if ( - err.body.error === DeploymentMutationError.VALIDATE_INPUT && - err.body.details !== undefined - ) { - let message = ""; - for (const key in err.body.details) { - message += ` ${brandColor(key)} ${err.body.details[key]}\n`; + try { + const maybeError = JSON.parse(err.body.error); + if ( + maybeError.error !== undefined && + maybeError.details !== undefined && + typeof maybeError.details === "object" + ) { + let message = ""; + for (const key in maybeError.details) { + message += `${brandColor(key)} ${maybeError.details[key]}\n`; + } + return message; } - - return message; - } - - if (err.body.error !== undefined) { - return ` ${err.body.error}`; - } - + } catch {} + // if we can't make it pretty, just dump out the error body return JSON.stringify(err.body); } @@ -387,7 +382,7 @@ const doAction = async ( try { application = await promiseSpinner( ApplicationsService.createApplication(action.application), - { message: `Creating ${action.application.name}` } + { message: `Creating "${action.application.name}"` } ); } catch (err) { if (!(err instanceof Error)) { @@ -395,20 +390,18 @@ const doAction = async ( } if (!(err instanceof ApiError)) { - throw new UserError( + throw new FatalError( `Unexpected error creating application: ${err.message}` ); } if (err.status === 400) { throw new UserError( - `Error creating application due to a misconfiguration\n${formatError(err)}` + `Error creating application due to a misconfiguration:\n${formatError(err)}` ); } - throw new UserError( - `Error creating application due to an internal error (request id: ${err.body.request_id}):\n${formatError(err)}` - ); + throw new UserError(`Error creating application:\n${formatError(err)}`); } success( @@ -432,18 +425,18 @@ const doAction = async ( if (!(err instanceof ApiError)) { throw new UserError( - `Unexpected error modifying application ${action.name}: ${err.message}` + `Unexpected error modifying application "${action.name}": ${err.message}` ); } if (err.status === 400) { throw new UserError( - `Error modifying application ${action.name} due to a misconfiguration:\n\n\t${formatError(err)}` + `Error modifying application "${action.name}" due to a misconfiguration:\n\n\t${formatError(err)}` ); } throw new UserError( - `Error modifying application ${action.name} due to an internal error (request id: ${err.body.request_id}):\n${formatError(err)}` + `Error modifying application "${action.name}":\n${formatError(err)}` ); } @@ -468,18 +461,18 @@ const doAction = async ( if (!(err instanceof ApiError)) { throw new UserError( - `Unexpected error rolling out application ${action.name}:\n${err.message}` + `Unexpected error rolling out application "${action.name}":\n${err.message}` ); } if (err.status === 400) { throw new UserError( - `Error rolling out application ${action.name} due to a misconfiguration:\n\n\t${formatError(err)}` + `Error rolling out application "${action.name}" due to a misconfiguration:\n\n\t${formatError(err)}` ); } throw new UserError( - `Error rolling out application ${action.name} due to an internal error (request id: ${err.body.request_id}): ${formatError(err)}` + `Error rolling out application "${action.name}":\n${formatError(err)}` ); } } From 064abed778dcef483dee167bd9a5e87c18e09677 Mon Sep 17 00:00:00 2001 From: emily-shen Date: Tue, 12 Aug 2025 14:12:15 +0100 Subject: [PATCH 2/2] changeset --- .changeset/soft-donuts-grin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/soft-donuts-grin.md diff --git a/.changeset/soft-donuts-grin.md b/.changeset/soft-donuts-grin.md new file mode 100644 index 0000000000..60b04796c2 --- /dev/null +++ b/.changeset/soft-donuts-grin.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +print prettier errors during container deployment