clawwork-ai/ClawWork
在 GitHub 查看[Bug] readConfig silently returns null on parse errors, losing user config
Open
#384 创建于 2026年4月15日
area/artifactgood first issuekind/bug
仓库指标
- Star
- (519 star)
- PR 合并指标
- (PR 指标待抓取)
描述
Problem
readConfig wraps the whole read/parse/decrypt pipeline in a bare catch {} that returns null on any error. If the config file is corrupted (partial write, disk error, bad manual edit), the user sees a completely empty app — all gateway configurations, language settings, and preferences silently disappear. No error is logged and no backup is kept, so recovery is impossible.
Location
File: packages/desktop/src/main/workspace/config.ts:155-166
export function readConfig(): AppConfig | null {
const cfgPath = configFilePath();
if (!existsSync(cfgPath)) return null;
try {
const raw = readFileSync(cfgPath, 'utf-8');
const config = JSON.parse(raw) as AppConfig;
const migrated = migrateConfigIfNeeded(config);
return decryptGatewayCredentials(migrated);
} catch {
return null;
}
}
Fix Approach
- In the catch block, log the error via
console.error('[config] failed to read:', err). - Rename the corrupted file to
config.json.corrupted-<ISO timestamp>so the user has a recovery artifact on disk. - Return
nullas before, so the first-run flow still kicks in.
Verification
- Run
pnpm check— must pass. - Manual: write garbage into the config file, launch the app, check that:
- The corrupted file is renamed with a
.corrupted-*suffix. - The main process log contains the error.
- The app still launches into the first-run flow.
- The corrupted file is renamed with a
Context
- WG: Artifact & File System
- Priority: Low (good first issue)
- Estimated effort: 20-30 minutes