refactor(errors): extract top-level error handling into shared utility

This commit is contained in:
mitchell 2026-06-17 00:48:15 -04:00
parent 56352d87ec
commit f8e0f9a368
3 changed files with 26 additions and 16 deletions

View file

@ -2,11 +2,10 @@
import util from "node:util";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { streamText } from "ai";
import chalk from "chalk";
import wrapAnsi from "wrap-ansi";
import { initConfig, loadConfig } from "./src/config";
import { Conversation } from "./src/conversation";
import { handleTopLevel } from "./src/errors";
import Renderer from "./src/render";
async function main() {
@ -104,10 +103,4 @@ Review the above diff for any potential bugs, best practices, performance issues
await renderer.renderStats(totalUsage);
}
main().catch((err) => {
if ("message" in err) {
const [columns] = process.stderr.getWindowSize();
console.error(wrapAnsi(chalk.red(err.message), columns));
} else console.log(err);
process.exit(1);
});
main().catch(handleTopLevel);