Skip to content

Commit 82353b8

Browse files
committed
chore(cli): keep @fern-api/docker-utils as plain Error, add CONTAINER_ERROR wrappers at call sites
1 parent d5c8fd0 commit 82353b8

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

packages/cli/generation/local-generation/local-workspace-runner/src/ContainerExecutionEnvironment.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ContainerRunner } from "@fern-api/core-utils";
22
import { runContainer } from "@fern-api/docker-utils";
3+
import { CliError } from "@fern-api/task-context";
34
import {
45
CONTAINER_CODEGEN_OUTPUT_DIRECTORY,
56
CONTAINER_GENERATOR_CONFIG_PATH,
@@ -79,15 +80,25 @@ export class ContainerExecutionEnvironment implements ExecutionEnvironment {
7980
ports[DEFAULT_NODE_DEBUG_PORT] = DEFAULT_NODE_DEBUG_PORT;
8081
}
8182

82-
await runContainer({
83-
logger: context.logger,
84-
imageName: this.containerImage,
85-
args: [CONTAINER_GENERATOR_CONFIG_PATH],
86-
binds,
87-
envVars,
88-
ports,
89-
removeAfterCompletion: !this.keepContainer,
90-
runner: this.runner ?? runner
91-
});
83+
try {
84+
await runContainer({
85+
logger: context.logger,
86+
imageName: this.containerImage,
87+
args: [CONTAINER_GENERATOR_CONFIG_PATH],
88+
binds,
89+
envVars,
90+
ports,
91+
removeAfterCompletion: !this.keepContainer,
92+
runner: this.runner ?? runner
93+
});
94+
} catch (error) {
95+
if (error instanceof CliError) {
96+
throw error;
97+
}
98+
throw new CliError({
99+
message: `Container execution failed: ${error instanceof Error ? error.message : String(error)}`,
100+
code: CliError.Code.ContainerError
101+
});
102+
}
92103
}
93104
}

packages/cli/generation/local-generation/local-workspace-runner/src/ReusableContainerExecutionEnvironment.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from "@fern-api/docker-utils";
99
import { Logger, LogLevel } from "@fern-api/logger";
1010
import { loggingExeca } from "@fern-api/logging-execa";
11+
import { CliError } from "@fern-api/task-context";
1112
import {
1213
CONTAINER_CODEGEN_OUTPUT_DIRECTORY,
1314
CONTAINER_FERN_DIRECTORY,
@@ -90,7 +91,13 @@ export class ReusableContainerExecutionEnvironment implements ExecutionEnvironme
9091
}
9192
this.containers = [];
9293
this.availableContainers = [];
93-
throw error;
94+
if (error instanceof CliError) {
95+
throw error;
96+
}
97+
throw new CliError({
98+
message: `Failed to start containers: ${error instanceof Error ? error.message : String(error)}`,
99+
code: CliError.Code.ContainerError
100+
});
94101
}
95102

96103
if (isDebug) {
@@ -108,6 +115,14 @@ export class ReusableContainerExecutionEnvironment implements ExecutionEnvironme
108115
const containerId = await this.acquire();
109116
try {
110117
await this.doExecute(containerId, args);
118+
} catch (error) {
119+
if (error instanceof CliError) {
120+
throw error;
121+
}
122+
throw new CliError({
123+
message: `Container execution failed: ${error instanceof Error ? error.message : String(error)}`,
124+
code: CliError.Code.ContainerError
125+
});
111126
} finally {
112127
this.release(containerId);
113128
}

0 commit comments

Comments
 (0)