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 -3
View File
@@ -1,3 +1,5 @@
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
@@ -8,9 +10,7 @@ export function handleWorkerError(error: any): never {
error.name === 'TimeoutError' ||
error.message?.includes('fetch failed') ||
error.message?.includes('Unable to connect')) {
throw new Error(
"There's a problem with the worker. Try: npm run worker:restart"
);
throw new Error(getWorkerRestartInstructions());
}
throw error;
}
+9 -5
View File
@@ -6,6 +6,7 @@ import { logger } from "../utils/logger.js";
import { HOOK_TIMEOUTS, getTimeout } from "./hook-constants.js";
import { ProcessManager } from "../services/process/ProcessManager.js";
import { SettingsDefaultsManager } from "./SettingsDefaultsManager.js";
import { getWorkerRestartInstructions } from "../utils/error-messages.js";
const MARKETPLACE_ROOT = path.join(homedir(), '.claude', 'plugins', 'marketplaces', 'thedotmack');
@@ -197,9 +198,10 @@ export async function ensureWorkerRunning(): Promise<void> {
if (!started) {
const port = getWorkerPort();
throw new Error(
`Worker service failed to start on port ${port}.\n\n` +
`To start manually, run: npm run worker:start\n` +
`If already running, try: npm run worker:restart`
getWorkerRestartInstructions({
port,
customPrefix: `Worker service failed to start on port ${port}.`
})
);
}
@@ -217,7 +219,9 @@ export async function ensureWorkerRunning(): Promise<void> {
const port = getWorkerPort();
logger.error('SYSTEM', 'Worker started but not responding to health checks');
throw new Error(
`Worker service started but is not responding on port ${port}.\n\n` +
`Try: npm run worker:restart`
getWorkerRestartInstructions({
port,
customPrefix: `Worker service started but is not responding on port ${port}.`
})
);
}