ctrlshiftleft
Version:
AI-powered toolkit for embedding QA and security testing into development workflows
113 lines (112 loc) • 3.25 kB
TypeScript
/**
* Error Handler
*
* Comprehensive error handling and recovery utilities for ctrl.shift.left tools.
* Provides standardized error formatting, recovery strategies, and user guidance.
*/
/**
* Error code categories used for documentation linking and recovery strategies
*/
export declare enum ErrorCategory {
FILESYSTEM = "filesystem",
NETWORK = "network",
CONFIG = "configuration",
VALIDATION = "validation",
GENERATION = "generation",
EXECUTION = "execution",
SECURITY = "security",
FRAMEWORK = "framework",
PERMISSION = "permission",
UNKNOWN = "unknown"
}
/**
* Enhanced error structure with additional context and recovery information
*/
export interface EnhancedError {
message: string;
originalError?: Error;
code: string;
category: ErrorCategory;
recovery: string[];
docLink?: string;
context?: Record<string, any>;
}
/**
* Fallback templates for various operations when generation fails
*/
declare const FALLBACK_TEMPLATES: Record<string, string>;
/**
* Error handler class for standardizing error handling across ctrl.shift.left
*/
export declare class ErrorHandler {
private logPath;
private verbose;
private autoRecover;
constructor(options?: {
logPath?: string;
verbose?: boolean;
autoRecover?: boolean;
});
/**
* Process and enhance an error with additional context
* @param error Original error
* @param operation Operation that caused the error
* @param context Additional context information
* @returns Enhanced error object
*/
handleError(error: Error | string, operation: string, context?: Record<string, any>): EnhancedError;
/**
* Display a user-friendly error message
* @param error Enhanced error object
*/
displayError(error: EnhancedError): void;
/**
* Attempt to recover from an error
* @param error Enhanced error object
* @param fallbackType Type of fallback to generate
* @param outputPath Path to write fallback output
* @returns Success status and path to fallback if created
*/
attemptRecovery(error: EnhancedError, fallbackType?: keyof typeof FALLBACK_TEMPLATES, outputPath?: string): {
success: boolean;
fallbackPath?: string;
};
/**
* Recover from filesystem errors
*/
private recoverFromFilesystemError;
/**
* Recover from network errors
*/
private recoverFromNetworkError;
/**
* Recover from generation errors
*/
private recoverFromGenerationError;
/**
* Log an error to the error log file
*/
private logError;
/**
* Categorize an error based on its message and context
*/
private categorizeError;
/**
* Generate a unique error code for tracking and documentation
*/
private generateErrorCode;
/**
* Get recovery steps based on error category and context
*/
private getRecoverySteps;
/**
* Get documentation link for error category
*/
private getDocumentationLink;
/**
* Simple string hash function for generating error codes
*/
private hashString;
}
export declare const errorHandler: ErrorHandler;
export {};