UNPKG

@schemifyjs/core

Version:

Core module of the SchemifyJS CLI. Provides reusable functions such as scaffolding, template handling, and general utilities.

24 lines (23 loc) 886 B
import chalk from 'chalk'; import { CliErrorType } from './error-types.js'; export class ErrorHandler { static handle(error, options) { var _a; const exitCode = (_a = options === null || options === void 0 ? void 0 : options.exitCode) !== null && _a !== void 0 ? _a : 1; if (error instanceof Error) { this.logError(error); } else { console.error(chalk.red('❌ An unknown error occurred.')); } process.exit(exitCode); } static logError(error) { var _a; const isKnownCliError = Object.values(CliErrorType).includes(error.name); console.error(chalk.redBright(`\n❌ ${error.name}: ${error.message}`)); if (!isKnownCliError) { console.error(chalk.gray((_a = error.stack) !== null && _a !== void 0 ? _a : 'No stack trace available.')); } } }