fix: wrap RecoveryManager in try-catch to prevent blocking CLI commands

Recovery failures (permission errors, disk full) no longer block
--version/--help commands. Recovery is best-effort - warns on failure
but allows basic CLI functionality to continue.

Fixes edge case identified in PR #215 code review.
This commit is contained in:
kaitranntt committed 2025-12-27 12:25:59 -05:00
1 parent ec2ee0a36d
commit 2fff770b6b
1 file changed
+6
+6
View File
@@ -294,6 +294,8 @@ async function main(): Promise<void> {
// Auto-recovery for missing configuration (BEFORE any early-exit commands) // Auto-recovery for missing configuration (BEFORE any early-exit commands)
// This ensures ALL commands benefit from auto-recovery, not just profile-switching flow // This ensures ALL commands benefit from auto-recovery, not just profile-switching flow
// Recovery is safe to run early - it only creates missing files with safe defaults // Recovery is safe to run early - it only creates missing files with safe defaults
// Wrapped in try-catch to prevent blocking --version/--help on permission errors
try {
const RecoveryManagerModule = await import('./management/recovery-manager'); const RecoveryManagerModule = await import('./management/recovery-manager');
const RecoveryManager = RecoveryManagerModule.default; const RecoveryManager = RecoveryManagerModule.default;
const recovery = new RecoveryManager(); const recovery = new RecoveryManager();
@@ -302,6 +304,10 @@ async function main(): Promise<void> {
if (recovered) { if (recovered) {
recovery.showRecoveryHints(); recovery.showRecoveryHints();
} }
} catch (err) {
// Recovery is best-effort - don't block basic CLI functionality
console.warn('[!] Recovery failed:', (err as Error).message);
}
// Special case: version command (check BEFORE profile detection) // Special case: version command (check BEFORE profile detection)
if (firstArg === 'version' || firstArg === '--version' || firstArg === '-v') { if (firstArg === 'version' || firstArg === '--version' || firstArg === '-v') {