| 28 | * @param verbose Whether to show verbose output |
| 29 | */ |
| 30 | export function handleError(error: unknown, verbose = false): never { |
| 31 | if (error instanceof SparcBenchError) { |
| 32 | console.error(`[${error.code}] ${error.message}`); |
| 33 | |
| 34 | if (verbose && error.stack) { |
| 35 | console.error("\nStack trace:"); |
| 36 | console.error(error.stack); |
| 37 | } |
| 38 | } else if (error instanceof Error) { |
| 39 | console.error(`[ERROR] ${error.message}`); |
| 40 | |
| 41 | if (verbose && error.stack) { |
| 42 | console.error("\nStack trace:"); |
| 43 | console.error(error.stack); |
| 44 | } |
| 45 | } else { |
| 46 | console.error("[ERROR] An unknown error occurred:", error); |
| 47 | } |
| 48 | |
| 49 | Deno.exit(1); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Try to execute a function and handle any errors |