UNPKG

subtexty

Version:

Extract clean plain-text from subtitle files

83 lines 3.35 kB
/** * Custom error classes for better error handling and categorization */ export declare abstract class SubtextyError extends Error { readonly context?: Record<string, unknown> | undefined; abstract readonly code: string; abstract readonly exitCode: number; constructor(message: string, context?: Record<string, unknown> | undefined); } export declare abstract class FileError extends SubtextyError { readonly filePath: string; readonly exitCode = 1; constructor(message: string, filePath: string, context?: Record<string, unknown>); } export declare class FileNotFoundError extends FileError { readonly code: "FILE_NOT_FOUND"; constructor(filePath: string); } export declare class FileNotReadableError extends FileError { readonly code: "FILE_NOT_READABLE"; constructor(filePath: string); } export declare class OutputDirectoryError extends FileError { readonly code: "OUTPUT_DIR_NOT_EXIST"; constructor(directory: string); } export declare class WriteError extends FileError { readonly code: "WRITE_ERROR"; constructor(filePath: string, originalError?: Error); } export declare abstract class ParsingError extends SubtextyError { readonly format?: string | undefined; readonly exitCode = 2; constructor(message: string, format?: string | undefined, context?: Record<string, unknown>); } export declare class UnsupportedFormatError extends ParsingError { readonly code: "UNSUPPORTED_FORMAT"; constructor(extension: string); } export declare class InvalidFormatError extends ParsingError { readonly code: "INVALID_FORMAT"; constructor(format: string, details: string); } export declare abstract class ValidationError extends SubtextyError { readonly field?: string | undefined; readonly exitCode = 2; constructor(message: string, field?: string | undefined, context?: Record<string, unknown>); } export declare class InputValidationError extends ValidationError { readonly code: "INPUT_VALIDATION_ERROR"; constructor(field: string, reason: string); } export declare class GenericFileError extends FileError { readonly code: "FILE_ERROR"; } export declare class GenericParsingError extends ParsingError { readonly code: "PARSING_ERROR"; } export declare class GenericValidationError extends ValidationError { readonly code: "VALIDATION_ERROR"; } /** * Error factory for creating specific error types */ export declare class ErrorFactory { static fileNotFound(filePath: string): FileNotFoundError; static fileNotReadable(filePath: string): FileNotReadableError; static outputDirectoryNotExist(directory: string): OutputDirectoryError; static writeError(filePath: string, originalError?: Error): WriteError; static unsupportedFormat(extension: string): UnsupportedFormatError; static invalidFormat(format: string, details: string): InvalidFormatError; static inputValidation(field: string, reason: string): InputValidationError; static parsing(message: string, format?: string): GenericParsingError; } /** * Type guard to check if an error is a SubtextyError */ export declare function isSubtextyError(error: unknown): error is SubtextyError; /** * Get appropriate exit code from any error */ export declare function getExitCode(error: unknown): number; //# sourceMappingURL=errors.d.ts.map