bb0508d639
- Updated multiple hooks (context-hook, new-hook, save-hook, summary-hook, user-message-hook) to throw errors using `getWorkerRestartInstructions` for improved user guidance on worker connection issues. - Enhanced `handleWorkerError` function to utilize the new error message generator for consistent error reporting. - Modified `ensureWorkerRunning` function to provide detailed instructions based on the worker's state, including port information. - Introduced `getWorkerRestartInstructions` utility in `error-messages.ts` to generate platform-aware error messages for worker failures.
17 lines
650 B
TypeScript
17 lines
650 B
TypeScript
import { getWorkerRestartInstructions } from '../utils/error-messages.js';
|
|
|
|
/**
|
|
* Handles fetch errors by providing user-friendly messages for connection issues
|
|
* @throws Error with helpful message if worker is unreachable, re-throws original otherwise
|
|
*/
|
|
export function handleWorkerError(error: any): never {
|
|
if (error.cause?.code === 'ECONNREFUSED' ||
|
|
error.code === 'ConnectionRefused' || // Bun-specific error format
|
|
error.name === 'TimeoutError' ||
|
|
error.message?.includes('fetch failed') ||
|
|
error.message?.includes('Unable to connect')) {
|
|
throw new Error(getWorkerRestartInstructions());
|
|
}
|
|
throw error;
|
|
}
|