Skip to content

🛡️ Error handling & graceful degradation audit #228

Closed

Description

@hurttlocker

Problem

A stranger downloads Cortex, runs cortex import ~/notes --extract, and their OpenRouter key is expired. What happens? Right now: a one-line notice and rule-only fallback. But that's one path out of dozens.

Every CLI command needs to be walked through with the question: "What does a first-time user see when this goes wrong?"

Scope

Error Path Inventory

Walk every command (import, search, extract, classify, conflicts, stale, stats, graph, connect, embed, reason, cleanup, summarize, reimport, mcp) and catalog:

  • What happens with no DB file?
  • What happens with a corrupt/locked DB?
  • What happens with no API keys (OpenRouter, Ollama down, etc.)?
  • What happens with empty input (no files, no facts, no matches)?
  • What happens with permissions errors (read-only dir, no write to ~/.cortex)?

Standards

  • No panics in any user-reachable path
  • No silent failures — every skip/fallback gets a one-line notice to stderr
  • Error messages include what went wrong + what to do (not just a Go stack trace)
  • Exit codes are meaningful (0=success, 1=error, 2=partial success)

Graceful Degradation Matrix

Document and test these degradation paths:

Missing Behavior Status
OpenRouter key Skip enrichment/classify, rule-only extract ✅ Done (v0.9.0)
Ollama Skip semantic search, BM25 only ⬜ Verify
No embeddings in DB Hybrid falls back to BM25 ⬜ Verify
Empty DB Helpful "import something first" message ⬜ Verify
Corrupt DB Clear error, suggest backup/reimport ⬜ Build
Read-only filesystem Clear error before any writes ⬜ Build

Acceptance Criteria

  • Every command tested with: missing DB, empty DB, no API keys, no Ollama
  • No panics reachable from CLI
  • Every error message includes remediation hint
  • Exit codes documented in --help or man page
  • At least 10 new error-path tests added to test suite

Activity

  1. added
    v1.0
    hardening
    on Feb 25, 2026
  2. hurttlocker commented on Feb 26, 2026

    @hurttlocker
    OwnerAuthor

    Closed. Error handling audit complete across 3 commits:

    ac5a54c — Core infrastructure:

    • exitWithError() centralized error handler with remediationHint()
    • Covers 8 error categories: usage, API keys (OpenRouter/Google/OpenAI), corrupt DB, locked DB, permission denied, missing DB, store open failures
    • Unknown command suggests cortex help
    • 40+ subprocess-based exit code tests

    89a9064 — Edge cases:

    • reinforce: returns error when no facts were reinforced
    • list --type: validates fact_type against 9 valid types
    • search: validates mode

    Verified across all 30+ commands:

    • No panics in any user-reachable path
    • No silent failures (every skip/fallback prints a notice to stderr)
    • Error messages include what went wrong + what to do
    • Exit codes: 0=success, 1=error
    • 847 test functions, all passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hardeningv1.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions