UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

170 lines (169 loc) 5.54 kB
import ts from "typescript"; /** * Error severity levels */ export declare enum ErrorSeverity { LOW = "low", MEDIUM = "medium", HIGH = "high", CRITICAL = "critical" } /** * Error categories for function analysis */ export declare enum ErrorCategory { PARSING = "parsing", TYPE_RESOLUTION = "type_resolution", AST_TRAVERSAL = "ast_traversal", FILE_ACCESS = "file_access", FUNCTION_EXTRACTION = "function_extraction", CLASSIFICATION = "classification", DEPENDENCY_ANALYSIS = "dependency_analysis" } /** * Structured error information */ export interface AnalysisError { category: ErrorCategory; severity: ErrorSeverity; message: string; context: string; filePath?: string; functionName?: string; nodeKind?: string; stackTrace?: string; timestamp: Date; recoverable: boolean; } /** * Error handling configuration */ export interface ErrorHandlingConfig { logErrors: boolean; throwOnCritical: boolean; maxErrorsPerFile: number; includeStackTrace: boolean; enableRecovery: boolean; } /** * Fallback values for when extraction fails */ export interface FallbackValues { functionName: string; returnType: string; params: string[]; body: string; dependencies: string[]; calledFunctions: string[]; isAsync: boolean; } /** * Utility class for structured error handling in function analysis */ export declare class ErrorHandler { private errors; private config; private readonly defaultFallbacks; constructor(config?: Partial<ErrorHandlingConfig>); /** * Safely executes a function with error handling and fallback */ safeExecute<T>(operation: () => T, fallbackValue: T, context: string, category?: ErrorCategory, severity?: ErrorSeverity, filePath?: string, functionName?: string): T; /** * Safely extracts function name with fallback */ safeFunctionName(node: ts.Node, extractor: (node: ts.Node) => string, filePath?: string): string; /** * Safely extracts return type with fallback */ safeReturnType(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, extractor: (node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction) => string, filePath?: string, functionName?: string): string; /** * Safely extracts parameters with fallback */ safeParameters(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, extractor: (node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction) => string[], filePath?: string, functionName?: string): string[]; /** * Safely extracts function body with fallback */ safeFunctionBody(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, extractor: (node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction) => string, filePath?: string, functionName?: string): string; /** * Safely extracts dependencies with fallback */ safeDependencies(node: ts.Node, extractor: (node: ts.Node) => string[], filePath?: string, functionName?: string): string[]; /** * Safely extracts called functions with fallback */ safeCalledFunctions(node: ts.Node, extractor: (node: ts.Node) => string[], filePath?: string, functionName?: string): string[]; /** * Safely detects async status with fallback */ safeAsyncDetection(node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction, detector: (node: ts.FunctionDeclaration | ts.MethodDeclaration | ts.ArrowFunction) => boolean, filePath?: string, functionName?: string): boolean; /** * Safely performs classification with fallback */ safeClassification<T>(node: ts.Node, classifier: (node: ts.Node) => T, fallbackValue: T, filePath?: string, functionName?: string): T; /** * Safely traverses AST with error recovery */ safeASTTraversal<T>(node: ts.Node, traverser: (node: ts.Node) => T, fallbackValue: T, filePath?: string): T; /** * Handles file access errors */ handleFileError(filePath: string, operation: string, error: unknown): void; /** * Core error handling method */ private handleError; /** * Extracts error message from various error types */ private extractErrorMessage; /** * Extracts stack trace from error */ private extractStackTrace; /** * Attempts to extract TypeScript node kind from error context */ private extractNodeKind; /** * Logs error with appropriate level */ private logError; /** * Gets error count for a specific file */ private getErrorCountForFile; /** * Gets all errors */ getErrors(): AnalysisError[]; /** * Gets errors by category */ getErrorsByCategory(category: ErrorCategory): AnalysisError[]; /** * Gets errors by severity */ getErrorsBySeverity(severity: ErrorSeverity): AnalysisError[]; /** * Gets errors for a specific file */ getErrorsForFile(filePath: string): AnalysisError[]; /** * Clears all errors */ clearErrors(): void; /** * Gets error summary statistics */ getErrorSummary(): { total: number; bySeverity: Record<ErrorSeverity, number>; byCategory: Record<ErrorCategory, number>; filesWithErrors: number; }; /** * Checks if analysis can continue based on error state */ canContinueAnalysis(): boolean; }