UNPKG

cloc-graph

Version:

Track lines of code over time by language with visualization

54 lines (53 loc) 1.44 kB
"use strict"; /** * Error handling utilities */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorTypes = exports.AppError = void 0; exports.handleError = handleError; /** * Custom application error class with enhanced properties */ class AppError extends Error { constructor(message, code = 'GENERAL_ERROR', exitCode = 1) { super(message); this.name = this.constructor.name; this.code = code; this.exitCode = exitCode; Error.captureStackTrace(this, this.constructor); } } exports.AppError = AppError; /** * Handles application errors in a consistent way * * @param error - The error to handle * @returns Exit code to use when terminating the process */ function handleError(error) { if (error instanceof AppError) { console.error(`Error [${error.code}]: ${error.message}`); return error.exitCode; } else if (error instanceof Error) { console.error(`Unexpected error: ${error.message}`); if (error.stack) { console.debug(error.stack); } return 1; } else { console.error('Unknown error:', error); return 1; } } /** * Common error types */ exports.ErrorTypes = { INVALID_ARGUMENTS: 'INVALID_ARGUMENTS', REPOSITORY_ERROR: 'REPOSITORY_ERROR', CLOC_ERROR: 'CLOC_ERROR', CHART_ERROR: 'CHART_ERROR', FILE_SYSTEM_ERROR: 'FILE_SYSTEM_ERROR', };