Skip to content

Commit ae27e06

Browse files
author
Hweinstock
committed
fix(errors): swap tty error to invalidEnvironmentError
1 parent 646af27 commit ae27e06

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/globalConfig/accessor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class DefaultGlobalConfigAccessor implements GlobalConfigAccessor {
7676
private async writeToConfigFile(data: GlobalConfigFileData): Promise<GlobalConfigFileData> {
7777
const dataParseResult = globalConfigFileSchema.safeParse(data);
7878
if (!dataParseResult.success) {
79-
throw new InternalValidationError("failed to valide config data before writing to file", {
79+
throw new InternalValidationError("failed to validate config data before writing to file", {
8080
cause: dataParseResult.error,
8181
});
8282
}

src/tui/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import type { AppIO } from "../io";
1212
import type { Core } from "../handlers/types";
1313
import { JsonKey } from "../handlers/keys";
14+
import { AgentCoreCLIError, ERROR_SOURCE, type AgentCoreCLIErrorOptions } from "../errors";
1415

1516
// renderJson pretty-prints a value as indented JSON. It is the output
1617
// counterpart to renderTui: handlers call it to emit machine-readable results
@@ -43,7 +44,7 @@ export async function renderTuiAt(
4344
io: AppIO,
4445
): Promise<void> {
4546
if (!io.stdin.isTTY || !io.stdout.isTTY) {
46-
throw new TypeError("interactive mode requires a TTY on stdin and stdout");
47+
throw new InvalidEnvironmentError("interactive mode requires a TTY on stdin and stdout");
4748
}
4849

4950
// alternateScreen switches the terminal to its alternate buffer so the TUI
@@ -74,3 +75,10 @@ export function renderTui(core: Core, io: AppIO): DefaultHandle {
7475
await renderTuiAt(ctx.require(PathKey), ctx, core, io);
7576
};
7677
}
78+
79+
/** Error raised when detecting an invalid environment */
80+
export class InvalidEnvironmentError extends AgentCoreCLIError {
81+
constructor(message?: string, options?: Omit<AgentCoreCLIErrorOptions, "source">) {
82+
super(message, { ...options, source: ERROR_SOURCE.USER });
83+
}
84+
}

src/tui/tui.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect, describe } from "bun:test";
22
import { createRootHandler } from "../handlers";
3-
import { renderJson } from "./index";
3+
import { InvalidEnvironmentError, renderJson } from "./index";
44
import {
55
createSilentLogger,
66
TestCoreClient,
@@ -89,9 +89,7 @@ describe("TUI stream boundary", () => {
8989
globalConfigAccessor: new TestGlobalConfigAccessor(),
9090
});
9191

92-
await expect(root.route(["node", "agentcore"])).rejects.toThrow(
93-
"interactive mode requires a TTY on stdin and stdout",
94-
);
92+
await expect(root.route(["node", "agentcore"])).rejects.toThrow(InvalidEnvironmentError);
9593
},
9694
);
9795

0 commit comments

Comments
 (0)