feat: add type-safe error handling utilities

- Add isError() type guard to check if value is Error instance
- Add getErrorMessage() utility for safe error message extraction
  in catch blocks (handles TypeScript 4.4+ unknown error type)
- Replace all (err as Error).message patterns with getErrorMessage(err)
  across server.ts, cli.ts, ralph-loop.ts, and screen-manager.ts
- Follows TypeScript best practice of treating caught errors as unknown

This improves code safety by properly handling the case where caught
values may not be Error instances (e.g., thrown strings or objects).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkonandClaude Opus 4.5 committed 2026-01-21 14:07:04 +01:00
1 parent c33d6e0987
commit 384350f731
5 files changed
+74 -32

No files matched your search

+2 -2
View File
@@ -19,7 +19,7 @@ import { spawn, execSync } from 'node:child_process';
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { homedir } from 'node:os';
import { ScreenSession, ProcessStats, ScreenSessionWithStats } from './types.js';
import { ScreenSession, ProcessStats, ScreenSessionWithStats, getErrorMessage } from './types.js';
/** Path to persisted screen session metadata */
const SCREENS_FILE = join(homedir(), '.claudeman', 'screens.json');
@@ -213,7 +213,7 @@ export class ScreenManager extends EventEmitter {
return screen;
} catch (err) {
throw new Error(`Failed to create screen: ${(err as Error).message}`);
throw new Error(`Failed to create screen: ${getErrorMessage(err)}`);
}
}