create-electron-foundation
Version:
An interactive CLI to bootstrap a modern, type-safe, and scalable Electron application.
37 lines (36 loc) • 1.1 kB
JavaScript
export class CLIError extends Error {
constructor(message, code, recoverable = false, cause) {
super(message);
this.code = code;
this.recoverable = recoverable;
this.cause = cause;
this.name = 'CLIError';
}
}
export class FileSystemError extends CLIError {
constructor(message, path, cause) {
super(message, 'FILESYSTEM_ERROR', false, cause);
this.path = path;
}
}
export class TemplateError extends CLIError {
constructor(message, templateKey, cause) {
super(message, 'TEMPLATE_ERROR', true, cause);
this.templateKey = templateKey;
}
}
export class ValidationError extends CLIError {
constructor(message, field, cause) {
super(message, 'VALIDATION_ERROR', true, cause);
this.field = field;
}
}
export function handleError(error) {
if (error instanceof CLIError) {
return error;
}
if (error instanceof Error) {
return new CLIError(error.message, 'UNKNOWN_ERROR', false, error);
}
return new CLIError(String(error), 'UNKNOWN_ERROR', false);
}