Enhance error handling and logging in early-settings and worker-utils

- Added silent debugging for settings file loading failures in early-settings.ts.
- Improved error logging in worker-utils.ts for health check and worker startup failures, including detailed error information and context.
This commit is contained in:
Alex Newman
2025-12-09 14:04:32 -05:00
parent a2f7a4dc5a
commit 7cab32151e
11 changed files with 193 additions and 162 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
import { join } from 'path';
import { homedir } from 'os';
import { existsSync, readFileSync } from 'fs';
import { silentDebug } from '../utils/silent-debug.js';
const SETTINGS_PATH = join(homedir(), '.claude-mem', 'settings.json');
@@ -23,8 +24,8 @@ export function loadEarlySetting(key: keyof EarlySettings, defaultValue: string)
const fileValue = data.env?.[key];
if (fileValue !== undefined) return fileValue;
}
} catch {
// Fail silently - fall through to env var
} catch (error) {
silentDebug('Failed to load settings file', { error, settingsPath: SETTINGS_PATH, key });
}
return process.env[key] || defaultValue;
+12 -2
View File
@@ -3,6 +3,7 @@ import { existsSync } from "fs";
import { homedir } from "os";
import { spawnSync } from "child_process";
import { SettingsDefaultsManager } from "../services/worker/settings/SettingsDefaultsManager.js";
import { logger } from "../utils/logger.js";
// CRITICAL: Always use marketplace directory for PM2/ecosystem
// This ensures cross-platform compatibility and avoids cache directory confusion
@@ -34,7 +35,11 @@ async function isWorkerHealthy(): Promise<boolean> {
signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS)
});
return response.ok;
} catch {
} catch (error) {
logger.debug('SYSTEM', 'Worker health check failed', {
error: error instanceof Error ? error.message : String(error),
errorType: error?.constructor?.name
});
return false;
}
}
@@ -102,7 +107,12 @@ async function startWorker(): Promise<boolean> {
return false;
} catch (error) {
// Failed to start worker
logger.error('SYSTEM', 'Failed to start worker', {
platform: process.platform,
workerScript: path.join(MARKETPLACE_ROOT, 'plugin', 'scripts', 'worker-service.cjs'),
error: error instanceof Error ? error.message : String(error),
marketplaceRoot: MARKETPLACE_ROOT
});
return false;
}
}