/** * Enhanced Error System for @moicad/sdk Runtime * * Provides: * - Categorized error types (SYNTAX, LOGIC, SYSTEM) * - Error severity levels (WARNING, ERROR, CRITICAL) * - Smart error detection (missing return, wrong exports, etc.) * - Adaptive error messages based on context * - Actionable suggestions and code examples * - Stack trace parsing and code snippet extraction */ /** * Error category based on user action * - SYNTAX: User made a syntax/parsing mistake * - LOGIC: User made a logical/semantic mistake * - SYSTEM: System/environment issue (WASM crash, timeout, etc.) */ export declare enum ErrorCategory { SYNTAX = "syntax", LOGIC = "logic", SYSTEM = "system" } /** * Error severity level * - WARNING: Non-fatal, execution may continue with caveats * - ERROR: Fatal, execution cannot proceed * - CRITICAL: System failure requiring intervention */ export declare enum ErrorSeverity { WARNING = "warning", ERROR = "error", CRITICAL = "critical" } /** * Specific error codes (hierarchical: category.specific) * Used for: * - Programmatic error handling * - Analytics and error tracking * - Localization/i18n keys * - Documentation links */ export declare enum ErrorCode { SYNTAX_PARSE_ERROR = "syntax.parse_error", SYNTAX_INVALID_TOKEN = "syntax.invalid_token", SYNTAX_UNEXPECTED_EOF = "syntax.unexpected_eof", LOGIC_MISSING_EXPORT = "logic.missing_export", LOGIC_MISSING_RETURN = "logic.missing_return", LOGIC_INVALID_EXPORT_TYPE = "logic.invalid_export_type", LOGIC_FORBIDDEN_IMPORT = "logic.forbidden_import", LOGIC_UNDEFINED_VARIABLE = "logic.undefined_variable", LOGIC_NULL_GEOMETRY = "logic.null_geometry", SYSTEM_RUNTIME_ERROR = "system.runtime_error", SYSTEM_TIMEOUT = "system.timeout", SYSTEM_WASM_CRASH = "system.wasm_crash", SYSTEM_MEMORY_EXCEEDED = "system.memory_exceeded", SYSTEM_NETWORK = "system.network" } /** * Enhanced error interface with metadata for smart error handling * Includes context information, suggestions, and actionable help */ export interface EnhancedError { category: ErrorCategory; severity: ErrorSeverity; code: ErrorCode; message: string; line?: number; column?: number; stack?: string; codeSnippet?: string; context?: string; suggestion?: string; fixExample?: string; documentation?: string; originalError?: Error; } /** * Detect if a function is missing a return statement * * Heuristics: * 1. Result is undefined * 2. Exported value is a function * 3. Function body doesn't contain 'return' keyword * * @param result - The evaluated result from function call * @param exportedValue - The exported function value * @param code - Original source code (optional, for analysis) * @returns true if missing return is likely */ export declare function detectMissingReturn(result: any, exportedValue: any, code?: string): boolean; /** * Parse JavaScript error stack trace to extract line and column numbers * * Handles multiple stack trace formats: * - V8 (Chrome, Node.js): "at functionName (file:line:column)" * - Firefox: "functionName@file:line:column" * - Safari: "functionName@file:line:column" * * @param error - The error object with stack trace * @returns Object with line, column, and full stack */ export declare function parseJavaScriptStack(error: Error): { line?: number; column?: number; stack: string; }; /** * Extract code snippet around a specific line * * Shows context lines before and after the error line * with line numbers and an arrow pointing to the error line * * @param code - Full source code * @param line - Line number (1-indexed) * @param contextLines - Number of lines to show before/after (default: 2) * @returns Formatted code snippet string */ export declare function extractCodeSnippet(code: string, line: number, contextLines?: number): string; /** * Create an adaptive suggestion based on error code and context * * Returns detailed suggestions for LOGIC errors (user mistakes) * and concise messages for SYSTEM errors (environment issues) * * @param code - Error code enum * @param context - Additional context for the suggestion * @returns Suggestion string (may include newlines) */ export declare function createSuggestion(code: ErrorCode, context?: { exportType?: string; functionName?: string; importedModule?: string; expectedType?: string; }): string; /** * Create a code example showing how to fix the error * * Provides copy-paste ready code examples for common mistakes * * @param code - Error code enum * @param context - Additional context (function name, etc.) * @returns Code example string */ export declare function createFixExample(code: ErrorCode, context?: { functionName?: string; }): string; /** * Get documentation URL for an error code * * Links users to relevant documentation for learning more * * @param code - Error code enum * @returns Full documentation URL */ export declare function getDocumentationURL(code: ErrorCode): string; /** * Determine error verbosity level based on category * * Adaptive verbosity: * - LOGIC errors: Detailed (user mistakes need help) * - SYNTAX errors: Detailed (user mistakes need help) * - SYSTEM errors: Concise (environment issues are usually not user's fault) * * @param category - Error category enum * @returns Verbosity level */ export declare function getVerbosityLevel(category: ErrorCategory): 'concise' | 'detailed'; /** * Map error code to category * Useful for programmatic error handling * * @param code - Error code enum * @returns Error category enum */ export declare function getErrorCategory(code: ErrorCode): ErrorCategory; /** * Create a formatted error message for display * Includes category emoji, code, and message * * @param error - Enhanced error object * @returns Formatted error string */ export declare function formatErrorForDisplay(error: EnhancedError): string; //# sourceMappingURL=errors.d.ts.map