errors
This commit is contained in:
parent
24ce536873
commit
8dc8cb65db
|
|
@ -1,3 +1,3 @@
|
|||
export default function (...args: string[]): string {
|
||||
function (...args: string[]): string {
|
||||
return args.join(" ")
|
||||
}
|
||||
11
src/shell.ts
11
src/shell.ts
|
|
@ -20,7 +20,7 @@ export async function runCommand(input: string): Promise<CommandResult> {
|
|||
[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())
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user