@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
64 lines • 1.94 kB
TypeScript
import type { ErrorCode } from './codes';
import type { ErrorContext } from './types';
/**
* Create a standardized error message in any format
*/
export declare function formatError(options: ErrorMessageOptions): StandardizedError;
/**
* Quick helper for creating inline error messages (for template output)
*/
export declare function inlineError(type: string, message: string, code?: ErrorCode): string;
/**
* Quick helper for creating console error messages
*/
export declare function consoleError(type: string, message: string, filePath?: string, line?: number, code?: ErrorCode): string;
/**
* Enhanced error reporting with better context
*/
export declare function createEnhancedError(type: string, message: string, context: ErrorContext): string;
/**
* Safe wrapper for potentially dangerous operations
*/
export declare function safeExecute<T>(operation: () => T, fallback: T, errorHandler?: (error: Error) => void): T;
/**
* Async version of safe wrapper
*/
export declare function safeExecuteAsync<T>(operation: () => Promise<T>, fallback: T, errorHandler?: (error: Error) => void): Promise<T>;
/**
* Standardized error message options
*/
export declare interface ErrorMessageOptions {
type: string
message: string
code?: ErrorCode
filePath?: string
line?: number
column?: number
template?: string
offset?: number
snippet?: string
suggestion?: string
format?: ErrorOutputFormat
}
/**
* Standardized error message result
*/
export declare interface StandardizedError {
formatted: string
data: {
type: string
code: number | undefined
codeName: string | undefined
message: string
filePath: string | undefined
line: number | undefined
column: number | undefined
snippet: string | undefined
suggestion: string | undefined
timestamp: string
}
}
/**
* Error output format options
*/
export type ErrorOutputFormat = 'html' | 'text' | 'json' | 'console'