xonecas.io
64875
Mc

mini-coder / commit a0dd567

refactor(cli): fix circular dependency, fold error-render.ts into output.ts

output.ts imported renderError from error-render.ts, while error-render.ts
imported G/writeln from output.ts — a circular dependency.

Merging error-render.ts into output.ts eliminates the cycle: output.ts
now directly defines renderError and RenderedError using its own G/writeln.

Consumers of RenderedError (stream-render.ts, index.ts) updated to import
from output.ts.

xonecas2026-03-14 a0dd567ee696825167cc481bc0105c733c508695 parent c19e1c0

4 files changed

src/cli/error-render.ts+0−26
@@ -1,26 +0,0 @@
1-import * as c from "yoctocolors";
2-import { logError } from "./error-log.ts";
3-import { parseAppError } from "./error-parse.ts";
4-import { G, writeln } from "./output.ts";
5-
6-/**
7- * Thrown after an error has already been rendered to the terminal.
8- * Outer catch blocks can check for this to avoid re-displaying the same error.
9- */
10-export class RenderedError extends Error {
11- public readonly cause: unknown;
12- constructor(cause: unknown) {
13- super("already rendered");
14- this.name = "RenderedError";
15- this.cause = cause;
16- }
17-}
18-
19-export function renderError(err: unknown, context = "render"): void {
20- logError(err, context);
21- const parsed = parseAppError(err);
22- writeln(`${G.err} ${c.red(parsed.headline)}`);
23- if (parsed.hint) {
24- writeln(` ${c.dim(parsed.hint)}`);
25- }
26-}
src/cli/output.ts+26−3
@@ -10,7 +10,8 @@ import type {
1010 import type { TurnEvent } from "../llm-api/types.ts";
1111 import { loadAgents } from "./agents.ts";
1212 import { loadCustomCommands } from "./custom-commands.ts";
13-import { renderError } from "./error-render.ts";
13+import { logError } from "./error-log.ts";
14+import { parseAppError } from "./error-parse.ts";
1415 import { Spinner } from "./spinner.ts";
1516 import { renderStatusBar } from "./status-bar.ts";
1617 import { renderTurn } from "./stream-render.ts";
@@ -18,8 +19,6 @@ import { loadSkillsIndex } from "./skills.ts";
1819 import { terminal } from "./terminal-io.ts";
1920 import { renderHook } from "./tool-render.ts";
2021
21-export { renderError } from "./error-render.ts";
22-
2322 const HOME = homedir();
2423 declare const __PACKAGE_VERSION__: string;
2524 const PACKAGE_VERSION =
@@ -84,6 +83,30 @@ export const PREFIX = {
8483 success: G.ok,
8584 };
8685
86+// ─── Error handling ───────────────────────────────────────────────────────────
87+
88+/**
89+ * Thrown after an error has already been rendered to the terminal.
90+ * Outer catch blocks can check for this to avoid re-displaying the same error.
91+ */
92+export class RenderedError extends Error {
93+ public readonly cause: unknown;
94+ constructor(cause: unknown) {
95+ super("already rendered");
96+ this.name = "RenderedError";
97+ this.cause = cause;
98+ }
99+}
100+
101+export function renderError(err: unknown, context = "render"): void {
102+ logError(err, context);
103+ const parsed = parseAppError(err);
104+ writeln(`${G.err} ${c.red(parsed.headline)}`);
105+ if (parsed.hint) {
106+ writeln(` ${c.dim(parsed.hint)}`);
107+ }
108+}
109+
87110 // ─── Banner ───────────────────────────────────────────────────────────────────
88111
89112 /** Discover which context/config files exist for display in the banner. */
src/cli/stream-render.ts+1−1
@@ -4,7 +4,7 @@ import type { CoreMessage } from "../llm-api/turn.ts";
44 import type { TurnEvent } from "../llm-api/types.ts";
55 import { logError } from "./error-log.ts";
66 import { parseAppError } from "./error-parse.ts";
7-import { RenderedError } from "./error-render.ts";
7+import { RenderedError } from "./output.ts";
88
99 import { renderLine } from "./markdown.ts";
1010 import { G, write, writeln } from "./output.ts";
src/index.ts+1−1
@@ -7,7 +7,7 @@ import { loadAgents } from "./cli/agents.ts";
77 import { parseArgs, printHelp } from "./cli/args.ts";
88 import { bootstrapGlobalDefaults } from "./cli/bootstrap.ts";
99 import { initErrorLog } from "./cli/error-log.ts";
10-import { RenderedError } from "./cli/error-render.ts";
10+import { RenderedError } from "./cli/output.ts";
1111 import { resolveFileRefs } from "./cli/file-refs.ts";
1212 import { HeadlessReporter } from "./cli/headless-reporter.ts";
1313 import { runInputLoop } from "./cli/input-loop.ts";