Skip to content

fix: replace empty catch blocks with meaningful error handling #60

@iamfj

Description

@iamfj

Problem

12 locations across the codebase use empty catch {} blocks that silently swallow errors. The most critical case is in token-storage.ts:

// src/common/token-storage.ts:41
try {
    const encrypted = fs.readFileSync(tokenPath, "utf8").trim();
    return decryptToken(encrypted);
} catch {
    return null; // corrupted token → user sees "No API token found"
}

A user with a corrupted token file gets "No API token found" instead of "Your stored token is corrupted" — sending them on a debugging wild goose chase.

All locations

File Line Impact
src/common/token-storage.ts 42 High — corrupted token invisible to user
src/commands/auth.ts 136, 142, 213, 229, 257 Medium — various auth flow fallbacks
src/services/file-service.ts 179, 262 Medium — file access/stat errors lost
src/common/identifier.ts 38 Low — intentional try-parse pattern
src/common/embed-parser.ts 62, 71 Low — URL parse fallback
src/commands/documents.ts 68 Low — URL parse fallback

Expected behavior

  • token-storage.ts: Distinguish between "file not found" (return null) and "decryption failed" (log warning to stderr, return null)
  • auth.ts: At minimum, add inline comments explaining what errors are expected
  • file-service.ts: Surface the underlying error message in the result
  • Low-impact locations: Add a comment explaining the intentional swallow, or narrow the catch to expected error types

Acceptance criteria

  • No empty catch {} blocks remain without either error handling or an explanatory comment
  • token-storage.ts prints a warning to stderr when decryption fails
  • All existing tests still pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions