UNPKG

local-agent

Version:

A CLI agentic system for orchestrating tools and memory with per-folder scoping

56 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleError = handleError; exports.withErrorHandling = withErrorHandling; /** * @fileoverview * Centralized error handling utilities. */ const application_error_1 = require("./application-error"); /** * Centralized error handler that formats and logs application errors consistently. * * @param error The error to handle * @param context Optional context information for better error reporting */ function handleError(error, context) { const prefix = '[local-agent]'; const contextStr = context ? ` (${context})` : ''; if (error instanceof application_error_1.ApplicationError) { console.error(`${prefix} ${error.code}: ${error.message}${contextStr}`); if (!error.recoverable) { process.exit(1); } } else { const message = error instanceof Error ? error.message : String(error); console.error(`${prefix} Unexpected error: ${message}${contextStr}`); } } /** * Wraps a function to provide automatic error handling. * * @param fn The function to wrap * @param context Context information for error reporting * @returns The wrapped function */ function withErrorHandling(fn, context) { return ((...args) => { try { const result = fn(...args); // Handle async functions if (result instanceof Promise) { return result.catch((error) => { handleError(error, context); throw error; }); } return result; } catch (error) { handleError(error, context); throw error; } }); } //# sourceMappingURL=error-handler.js.map