From 8dc8cb65db714a9e73482a8b1634e57adbdda734 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 20 Sep 2025 19:19:58 -0700 Subject: [PATCH] errors --- nose/bin/echo.ts | 2 +- src/shell.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nose/bin/echo.ts b/nose/bin/echo.ts index 0e06a22..692c110 100644 --- a/nose/bin/echo.ts +++ b/nose/bin/echo.ts @@ -1,3 +1,3 @@ -export default function (...args: string[]): string { +function (...args: string[]): string { return args.join(" ") } \ No newline at end of file diff --git a/src/shell.ts b/src/shell.ts index 9fd75fa..bfada13 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -20,7 +20,7 @@ export async function runCommand(input: string): Promise { [status, output] = await exec(cmd, args) } catch (err) { status = "error" - output = err instanceof Error ? err.message : String(err) + output = errorMessage(err) } console.log("cmd", cmd) @@ -33,6 +33,15 @@ function commandExists(cmd: string): boolean { return isFile(join(NOSE_BIN, cmd + ".ts")) } +function errorMessage(error: Error | any): string { + if (!(error instanceof Error)) + return String(error) + + let msg = `${error.name}: ${error.message}` + if (error.stack) msg += `\n${error.stack}` + return msg +} + async function exec(cmd: string, args: string[]): Promise<["ok" | "error", string]> { const path = join(NOSE_BIN, cmd + ".ts") const module = await import(path + "?t+" + Date.now())