Refactor error handling to use platform-specific worker restart instructions

- 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.
This commit is contained in:
Alex Newman
2025-12-13 17:06:45 -05:00
parent f00ef33f86
commit bb0508d639
17 changed files with 192 additions and 112 deletions
+3 -2
View File
@@ -4,6 +4,7 @@ import { createHookResponse } from './hook-response.js';
import { ensureWorkerRunning, getWorkerPort } from '../shared/worker-utils.js';
import { happy_path_error__with_fallback } from '../utils/silent-debug.js';
import { handleWorkerError } from '../shared/hook-error-handler.js';
import { getWorkerRestartInstructions } from '../utils/error-messages.js';
export interface UserPromptSubmitInput {
session_id: string;
@@ -52,7 +53,7 @@ async function newHook(input?: UserPromptSubmitInput): Promise<void> {
if (!initResponse.ok) {
const errorText = await initResponse.text();
throw new Error(`Failed to initialize session: ${initResponse.status} ${errorText}`);
throw new Error(getWorkerRestartInstructions({ includeSkillFallback: true }));
}
const initResult = await initResponse.json();
@@ -86,7 +87,7 @@ async function newHook(input?: UserPromptSubmitInput): Promise<void> {
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to start SDK agent: ${response.status} ${errorText}`);
throw new Error(getWorkerRestartInstructions({ includeSkillFallback: true }));
}
} catch (error: any) {
handleWorkerError(error);