Skip to content

Commit ba41e68

Browse files
committed
refactor(dev): move CommandFailedError and MissingCodeDirectoryError to src/errors
All typed errors live in src/errors; the dev module was defining its own inline.
1 parent 5bc055a commit ba41e68

6 files changed

Lines changed: 31 additions & 28 deletions

File tree

src/core/dev/codezip.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { afterEach } from "bun:test";
66
import type { DevLogLevel, DevServerHandle } from "../../handlers/project/dev/types";
77
import type { ProjectRuntime } from "../../handlers/project/types";
88
import { createSilentLogger } from "../../testing";
9-
import { CodeZipDevRunner, MissingCodeDirectoryError, entrypointToAsgiApp } from "./codezip";
9+
import { MissingCodeDirectoryError } from "../../errors";
10+
import { CodeZipDevRunner, entrypointToAsgiApp } from "./codezip";
1011
import type { SpawnServerInput } from "./process";
1112

1213
const tempDirectories: string[] = [];

src/core/dev/codezip.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from "node:fs";
22
import { join } from "node:path";
3-
import { AgentCoreCLIError, ERROR_SOURCE } from "../../errors";
3+
import { MissingCodeDirectoryError } from "../../errors";
44
import type {
55
DevRunner,
66
DevServerHandle,
@@ -10,16 +10,6 @@ import type { Logger } from "../../logging";
1010
import { runCommand, type CommandRunner } from "./run";
1111
import { spawnServer, type SpawnServerInput } from "./process";
1212

13-
/** Error raised when a runtime's code directory is missing from the project. */
14-
export class MissingCodeDirectoryError extends AgentCoreCLIError {
15-
constructor(directory: string) {
16-
super(`runtime code directory not found: ${directory}`, {
17-
source: ERROR_SOURCE.USER,
18-
meta: { directory },
19-
});
20-
}
21-
}
22-
2313
type CodeZipDevRunnerConfig = {
2414
logger: Logger;
2515
/** Injectable process seams so tests never spawn uv or a real server. */

src/core/dev/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { CodeZipDevRunner, MissingCodeDirectoryError } from "./codezip";
1+
export { CodeZipDevRunner } from "./codezip";
22
export { spawnServer } from "./process";
3-
export { runCommand, CommandFailedError, type CommandRunner } from "./run";
3+
export { runCommand, type CommandRunner } from "./run";

src/core/dev/run.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { spawn } from "node:child_process";
2-
import { AgentCoreCLIError, ERROR_SOURCE } from "../../errors";
2+
import { CommandFailedError } from "../../errors";
33

44
// NOTE: shape-compatible with src/io/exec.ts from #1872; fold into that
55
// module once it lands so the CLI has one CommandRunner.
66

7-
/** Error raised when a subprocess exits non-zero, carrying its captured output. */
8-
export class CommandFailedError extends AgentCoreCLIError {
9-
constructor(command: string[], cwd: string, exitCode: number | null, output: string) {
10-
super(
11-
`'${command.join(" ")}' failed in ${cwd} (exit code ${exitCode ?? "unknown"}).\n\n${output.trim()}`,
12-
{
13-
source: ERROR_SOURCE.USER,
14-
meta: { command, cwd, exitCode },
15-
},
16-
);
17-
}
18-
}
19-
207
export type RunCommandOptions = {
218
/** Working directory the command runs in. */
229
cwd: string;

src/errors/errors.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ export class DeserializationError extends AgentCoreCLIError {
7979
}
8080
}
8181

82+
/** Error raised when a subprocess exits non-zero, carrying its captured output. */
83+
export class CommandFailedError extends AgentCoreCLIError {
84+
constructor(command: string[], cwd: string, exitCode: number | null, output: string) {
85+
super(
86+
`'${command.join(" ")}' failed in ${cwd} (exit code ${exitCode ?? "unknown"}).\n\n${output.trim()}`,
87+
{
88+
source: ERROR_SOURCE.USER,
89+
meta: { command, cwd, exitCode },
90+
},
91+
);
92+
}
93+
}
94+
95+
/** Error raised when a runtime's code directory is missing from the project. */
96+
export class MissingCodeDirectoryError extends AgentCoreCLIError {
97+
constructor(public readonly directory: string) {
98+
super(`runtime code directory not found: ${directory}`, {
99+
source: ERROR_SOURCE.USER,
100+
meta: { directory },
101+
});
102+
}
103+
}
104+
82105
/** Error raised when a command requires an AgentCore project and none encloses the working directory. */
83106
export class NoProjectError extends AgentCoreCLIError {
84107
constructor(searchPath: string, options?: Omit<AgentCoreCLIErrorOptions, "source">) {

src/errors/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export {
22
AgentCoreCLIError,
3+
CommandFailedError,
34
DeserializationError,
45
EmbeddedAssetNotFoundError,
56
InputValidationError,
67
InvalidEnvironmentError,
78
InvalidProjectConfigError,
9+
MissingCodeDirectoryError,
810
NestedProjectError,
911
NoProjectError,
1012
NotImplementedError,

0 commit comments

Comments
 (0)