UNPKG

@signalwire/docusaurus-plugin-llms-txt

Version:

Generate Markdown versions of Docusaurus HTML pages and an llms.txt index file

134 lines (133 loc) 3.16 kB
/** * Domain-specific error types for the plugin * Follows the development rules for typed error handling */ /** * Abstract base class for all plugin-specific errors */ export class PluginError extends Error { constructor(message, _context) { super(message); this._context = _context; this.name = this.constructor.name; } get context() { return this._context; } } /** * Configuration-related errors */ export class PluginConfigError extends PluginError { constructor() { super(...arguments); this.code = 'PLUGIN_CONFIG_ERROR'; } } /** * Processing-related errors (HTML conversion, file processing) * @internal */ export class PluginProcessingError extends PluginError { constructor() { super(...arguments); this.code = 'PLUGIN_PROCESSING_ERROR'; } } /** * Cache-related errors * @internal */ export class PluginCacheError extends PluginError { constructor() { super(...arguments); this.code = 'PLUGIN_CACHE_ERROR'; } } /** * File system operation errors * @internal */ export class PluginFileError extends PluginError { constructor() { super(...arguments); this.code = 'PLUGIN_FILE_ERROR'; } } /** * Validation errors */ export class PluginValidationError extends PluginError { constructor() { super(...arguments); this.code = 'PLUGIN_VALIDATION_ERROR'; } } /** * Type guard to check if an error is a plugin error */ export function isPluginError(error) { return error instanceof PluginError; } /** * Create a configuration error with context * @internal */ export function createConfigError(message, context) { return new PluginConfigError(message, context); } /** * Create a processing error with context * @internal */ export function createProcessingError(message, context) { return new PluginProcessingError(message, context); } /** * Create a cache error with context * @internal */ export function createCacheError(message, context) { return new PluginCacheError(message, context); } /** * Create a file error with context * @internal */ export function createFileError(message, context) { return new PluginFileError(message, context); } /** * Create a validation error with context * @internal */ export function createValidationError(message, context) { return new PluginValidationError(message, context); } // ============================================================================ // ERROR UTILITIES // ============================================================================ /** * Type guard to check if an unknown value is an Error * @internal */ export function isError(error) { return error instanceof Error; } /** * Safely extracts an error message from an unknown error value * @internal */ export function getErrorMessage(error) { if (isError(error)) { return error.message; } return String(error); } /** * Safely extracts an Error instance from an unknown error value * @internal */ export function getErrorCause(error) { return isError(error) ? error : undefined; }