UNPKG

@just-every/task

Version:
65 lines 2.2 kB
/** * Task Error Handling System * * Provides structured error handling for better debugging and user experience */ /** * Structured error class for Task system */ export class TaskError extends Error { component; agentName; modelId; task; metadata; originalError; timestamp; constructor(message, context, originalError) { const fullMessage = `[Task:${context.component}] ${message}`; super(fullMessage); this.name = 'TaskError'; this.component = context.component; this.agentName = context.agentName; this.modelId = context.modelId; this.task = context.task; this.metadata = context.metadata; this.originalError = originalError; this.timestamp = new Date(); // Maintain stack trace if (Error.captureStackTrace) { Error.captureStackTrace(this, TaskError); } } } /** * Validation error - thrown when input validation fails */ export class TaskValidationError extends TaskError { constructor(message, context, originalError) { super(message, { ...context, component: 'validation' }, originalError); this.name = 'TaskValidationError'; } } // Specialized error classes and validation functions removed // Only TaskError and TaskValidationError are used in the simplified API /** * Utility to wrap functions with error handling */ export function withErrorHandling(fn, component, context) { return ((...args) => { try { const result = fn(...args); // Handle async functions if (result instanceof Promise) { return result.catch((error) => { throw new TaskError(`Async operation failed: ${error.message || String(error)}`, { component, ...context }, error instanceof Error ? error : new Error(String(error))); }); } return result; } catch (error) { throw new TaskError(`Operation failed: ${error.message || String(error)}`, { component, ...context }, error instanceof Error ? error : new Error(String(error))); } }); } //# sourceMappingURL=errors.js.map