Skip to content

Commit 67e4c2d

Browse files
committed
fix(cli): exit non-zero when the build log stream cannot be opened
Failing to open the stream and losing it mid-build leave the CLI in the same position, unable to confirm the deployment outcome, so both now use the same message and exit code.
1 parent 123f091 commit 67e4c2d

2 files changed

Lines changed: 34 additions & 33 deletions

File tree

.changeset/deploy-log-stream-disconnect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"trigger.dev": patch
33
---
44

5-
When the build log stream disconnects during a build server deploy, the CLI now explains that the deployment itself is still running and exits immediately with a non-zero code, instead of printing the raw stream error and hanging.
5+
When the build log stream cannot be opened or disconnects during a build server deploy, the CLI now explains that the deployment itself is unaffected and exits immediately with a non-zero code, since it can no longer confirm the outcome. Previously a disconnect printed the raw stream error and left the process hanging.

packages/cli-v3/src/commands/deploy.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { resolveAlwaysExternal } from "../build/externals.js";
2626
import { createContextArchive, getArchiveSize } from "../deploy/archiveContext.js";
2727
import { createBundleArchive } from "../deploy/bundleArchive.js";
2828
import {
29+
BuildLogRenderer,
2930
BuildLogsMode,
3031
createBuildLogRenderer,
3132
resolveBuildLogsMode,
@@ -2284,6 +2285,36 @@ function showFullBuildLogs(options: DeployCommandOptions) {
22842285
return resolveBuildLogsMode(options.buildLogs, buildLogsEnv(options)) === "full";
22852286
}
22862287

2288+
function buildLogStreamError(
2289+
error: unknown,
2290+
renderer: BuildLogRenderer,
2291+
deployment: Pick<InitializeDeploymentResponseBody, "version">,
2292+
rawDeploymentLink: string
2293+
): OutroCommandError {
2294+
renderer.finish("Log stream stopped", "failure");
2295+
2296+
logger.debug("Build log stream failed", { error });
2297+
2298+
const reason = (error instanceof Error ? error.message : String(error))
2299+
.replace(/\s+/g, " ")
2300+
.slice(0, 200);
2301+
2302+
log.error(`Build log stream failed: ${reason}`);
2303+
log.info(
2304+
"The deployment itself is unaffected and continues on the build server. Check the dashboard for the final status."
2305+
);
2306+
2307+
if (!isLinksSupported) {
2308+
log.info(`View deployment: ${rawDeploymentLink}`);
2309+
}
2310+
2311+
return new OutroCommandError(
2312+
`Version ${deployment.version} ${
2313+
isLinksSupported ? `| ${cliLink("View deployment", rawDeploymentLink)}` : ""
2314+
}`
2315+
);
2316+
}
2317+
22872318
async function followBuildServerDeployment({
22882319
deployment,
22892320
eventStream,
@@ -2319,45 +2350,15 @@ async function followBuildServerDeployment({
23192350
);
23202351

23212352
if (readSessionError) {
2322-
renderer.finish("Failed to query build progress", "abandoned");
2323-
log.warn(`Failed streaming build logs, open the deployment in the dashboard to view the logs`);
2324-
2325-
outro(
2326-
`Version ${deployment.version} is being deployed ${
2327-
isLinksSupported ? `| ${cliLink("View deployment", rawDeploymentLink)}` : ""
2328-
}`
2329-
);
2330-
2331-
return process.exit(0);
2353+
throw buildLogStreamError(readSessionError, renderer, deployment, rawDeploymentLink);
23322354
}
23332355

23342356
const [streamError, finalDeploymentEvent] = await tryCatch(
23352357
streamDeploymentEvents(readSession, renderer, () => abortController.abort())
23362358
);
23372359

23382360
if (streamError) {
2339-
renderer.finish("Log stream stopped", "failure");
2340-
2341-
logger.debug("Build log stream failed", { error: streamError });
2342-
2343-
const reason = (streamError instanceof Error ? streamError.message : String(streamError))
2344-
.replace(/\s+/g, " ")
2345-
.slice(0, 200);
2346-
2347-
log.error(`Build log stream failed: ${reason}`);
2348-
log.info(
2349-
"The deployment itself is unaffected and continues on the build server. Check the dashboard for the final status."
2350-
);
2351-
2352-
if (!isLinksSupported) {
2353-
log.info(`View deployment: ${rawDeploymentLink}`);
2354-
}
2355-
2356-
throw new OutroCommandError(
2357-
`Version ${deployment.version} ${
2358-
isLinksSupported ? `| ${cliLink("View deployment", rawDeploymentLink)}` : ""
2359-
}`
2360-
);
2361+
throw buildLogStreamError(streamError, renderer, deployment, rawDeploymentLink);
23612362
}
23622363

23632364
if (!renderer.started && !finalDeploymentEvent) {

0 commit comments

Comments
 (0)