Skip to content

[Bug] readConfig silently returns null on parse errors, losing user config #384

@samzong

Description

@samzong

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

  1. In the catch block, log the error via console.error('[config] failed to read:', err).
  2. Rename the corrupted file to config.json.corrupted-<ISO timestamp> so the user has a recovery artifact on disk.
  3. Return null as before, so the first-run flow still kicks in.

Verification

  1. Run pnpm check — must pass.
  2. 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.

Context

  • WG: Artifact & File System
  • Priority: Low (good first issue)
  • Estimated effort: 20-30 minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/artifactArtifact & File System WGgood first issueGood for newcomerskind/bugCategorizes issue or PR as related to a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions