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
+53
View File
@@ -0,0 +1,53 @@
/**
* Platform-aware error message generator for worker connection failures
*/
export interface WorkerErrorMessageOptions {
port?: number;
includeSkillFallback?: boolean;
customPrefix?: string;
}
/**
* Generate platform-specific worker restart instructions
* @param options Configuration for error message generation
* @returns Formatted error message with platform-specific paths and commands
*/
export function getWorkerRestartInstructions(
options: WorkerErrorMessageOptions = {}
): string {
const {
port,
includeSkillFallback = false,
customPrefix
} = options;
const isWindows = process.platform === 'win32';
// Platform-specific directory paths
const pluginDir = isWindows
? '%USERPROFILE%\\.claude\\plugins\\marketplaces\\thedotmack'
: '~/.claude/plugins/marketplaces/thedotmack';
// Platform-specific terminal name
const terminal = isWindows
? 'Command Prompt or PowerShell'
: 'Terminal';
// Build error message
const prefix = customPrefix || 'Worker service connection failed.';
const portInfo = port ? ` (port ${port})` : '';
let message = `${prefix}${portInfo}\n\n`;
message += `To restart the worker:\n`;
message += `1. Exit Claude Code completely\n`;
message += `2. Open ${terminal}\n`;
message += `3. Navigate to: ${pluginDir}\n`;
message += `4. Run: npm run worker:restart`;
if (includeSkillFallback) {
message += `\n\nIf that doesn't work, try: /troubleshoot`;
}
return message;
}