fix(entry): improve error message formatting
- Relocate `util.parseArgs()` inside the main function for cleaner scoping - Update `.catch` handlers in `index.ts` and `tts.ts` to wrap text to terminal width and colorize errors in red
This commit is contained in:
parent
f3146ab087
commit
56352d87ec
2 changed files with 33 additions and 25 deletions
9
index.ts
9
index.ts
|
|
@ -2,11 +2,14 @@
|
||||||
import util from "node:util";
|
import util from "node:util";
|
||||||
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
||||||
import { streamText } from "ai";
|
import { streamText } from "ai";
|
||||||
|
import chalk from "chalk";
|
||||||
|
import wrapAnsi from "wrap-ansi";
|
||||||
|
|
||||||
import { initConfig, loadConfig } from "./src/config";
|
import { initConfig, loadConfig } from "./src/config";
|
||||||
import { Conversation } from "./src/conversation";
|
import { Conversation } from "./src/conversation";
|
||||||
import Renderer from "./src/render";
|
import Renderer from "./src/render";
|
||||||
|
|
||||||
|
async function main() {
|
||||||
const { values: args, positionals } = util.parseArgs({
|
const { values: args, positionals } = util.parseArgs({
|
||||||
args: process.argv.slice(2),
|
args: process.argv.slice(2),
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -30,7 +33,6 @@ const { values: args, positionals } = util.parseArgs({
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const newConvo = args.new ?? args.n;
|
const newConvo = args.new ?? args.n;
|
||||||
const plainOut = args["plain-out"] ?? args.plain ?? !process.stdout.isTTY;
|
const plainOut = args["plain-out"] ?? args.plain ?? !process.stdout.isTTY;
|
||||||
const plainErr = args["plain-err"] ?? args.plain ?? !process.stderr.isTTY;
|
const plainErr = args["plain-err"] ?? args.plain ?? !process.stderr.isTTY;
|
||||||
|
|
@ -103,6 +105,9 @@ Review the above diff for any potential bugs, best practices, performance issues
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
console.error(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);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
5
tts.ts
5
tts.ts
|
|
@ -180,6 +180,9 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
console.error(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);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue