From 2e90397c6388bac4fb341bedecfddd5681ee5ae9 Mon Sep 17 00:00:00 2001 From: Harshi-Shah-CS Date: Wed, 18 Nov 2026 12:47:18 +0530 Subject: [PATCH] fix(deployments): word any 400 from cancel as cannot-be-cancelled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a deployment finishes between the CLI's in-progress check and the cancel request (often while the user reads the "Are you sure?" prompt), the server refuses the cancel with a 400 whose body is {"errors":[{}]}: no code and no message. The CLI did not recognise it and fell back to "Launch API request failed with status 400." The cancel endpoint only returns a 400 when the deployment can no longer be cancelled (an invalid UID is caught earlier by the deployment lookup), so treat any 400 from it as cancel-not-allowed and show the existing message: Deployment "" cannot be cancelled because it is no longer in progress. A refusal carrying the CANCEL_NOT_ALLOWED code is still recognised on any status. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/deployments/deployments.api.test.ts | 19 ++++++++++++++++--- src/deployments/deployments.api.ts | 8 +------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/deployments/deployments.api.test.ts b/src/deployments/deployments.api.test.ts index a7c9e7ec..a8d89fad 100644 --- a/src/deployments/deployments.api.test.ts +++ b/src/deployments/deployments.api.test.ts @@ -339,6 +339,8 @@ describe('DeploymentsApi', () => { ['the code', [{ code: 'launch.DEPLOYMENT.CANCEL_NOT_ALLOWED', message: 'x' }]], ['the raw message as the code', [{ code: CANCEL_NOT_ALLOWED_RAW_MESSAGE, message: CANCEL_NOT_ALLOWED_RAW_MESSAGE }]], ['the raw message alone', [{ message: CANCEL_NOT_ALLOWED_RAW_MESSAGE }]], + ['an empty error entry', [{}]], + ['another message', [{ message: 'something else' }]], ])('words a cancel refused with %s as the cancel-not-allowed message', async (_name, errors) => { const rejection = new LaunchApiError(400, errors, DEPLOYMENT_ERROR_MESSAGES); const client = { request: async () => Promise.reject(rejection) } as unknown as RestApiClient; @@ -355,13 +357,24 @@ describe('DeploymentsApi', () => { expect(failure.message).not.toBe(CANCEL_NOT_ALLOWED_RAW_MESSAGE); }); - it('leaves a 400 with another message, and a non-400 with the raw message, untouched on cancel', async () => { - const other = new LaunchApiError(400, [{ message: 'something else' }]); + it('words a non-400 cancel refused with the code as the cancel-not-allowed message, keeping its status', async () => { + const rejection = new LaunchApiError(409, [{ code: 'launch.DEPLOYMENT.CANCEL_NOT_ALLOWED', message: 'x' }]); + const client = { request: async () => Promise.reject(rejection) } as unknown as RestApiClient; + + const failure = (await new DeploymentsApi(client) + .cancel({ ...SCOPE, deployment: DEPLOYMENT }) + .catch((error: unknown) => error)) as LaunchApiError; + + expect(failure.status).toBe(409); + expect(failure.message).toBe(`Deployment "${DEPLOYMENT}" cannot be cancelled because it is no longer in progress.`); + }); + + it('leaves a non-400 refusal untouched on cancel', async () => { const wrongStatus = new LaunchApiError(409, [{ message: CANCEL_NOT_ALLOWED_RAW_MESSAGE }]); const notFound = new LaunchApiError(404, [{ code: 'launch.DEPLOYMENT.NOT_FOUND', message: 'x' }], DEPLOYMENT_ERROR_MESSAGES); const plain = new Error('boom'); - for (const rejection of [other, wrongStatus, notFound, plain]) { + for (const rejection of [wrongStatus, notFound, plain]) { const client = { request: async () => Promise.reject(rejection) } as unknown as RestApiClient; await expect(new DeploymentsApi(client).cancel({ ...SCOPE, deployment: DEPLOYMENT })).rejects.toBe(rejection); diff --git a/src/deployments/deployments.api.ts b/src/deployments/deployments.api.ts index 88f2514c..e172413c 100644 --- a/src/deployments/deployments.api.ts +++ b/src/deployments/deployments.api.ts @@ -4,7 +4,6 @@ import { isRecord } from '../core/values'; import { LaunchApiError } from '../transport/errors'; import { CANCEL_NOT_ALLOWED_CODE, - CANCEL_NOT_ALLOWED_RAW_MESSAGE, DEPLOYMENT_ERROR_MESSAGES, DEPLOYMENT_NOT_FOUND_CODE, cancelNotAllowedError, @@ -42,12 +41,7 @@ export interface RollbackDeploymentParams extends DeploymentScope { function isCancelNotAllowed(error: unknown): error is LaunchApiError { return ( error instanceof LaunchApiError && - error.errors.some( - (entry) => - entry.code === CANCEL_NOT_ALLOWED_CODE || - (error.status === 400 && - (entry.code === CANCEL_NOT_ALLOWED_RAW_MESSAGE || entry.message === CANCEL_NOT_ALLOWED_RAW_MESSAGE)), - ) + (error.status === 400 || error.errors.some((entry) => entry.code === CANCEL_NOT_ALLOWED_CODE)) ); }