Found during dogfooding v2.2.3-dev.44e8146
Severity: Medium
Commands: codegraph cycles, codegraph export, codegraph embed
Reproduction
mkdir /tmp/test-no-graph && cd /tmp/test-no-graph && npm init -y
npm install @optave/codegraph@2.2.3-dev.44e8146
npx codegraph cycles # crashes
npx codegraph export # crashes
npx codegraph embed # crashes
Expected behavior
All commands should show the same graceful error message as other commands:
No codegraph database found at <path>/.codegraph/graph.db.
Run "codegraph build" first to analyze your codebase.
Actual behavior
All three commands crash with an unhandled TypeError stack trace from better-sqlite3:
TypeError: Cannot open database because the directory does not exist
at new Database (node_modules/better-sqlite3/lib/database.js:65:9)
at Command.<anonymous> (src/cli.js:317:16)
Root cause
These three command handlers bypass the findDbPath() guard that most other commands use. They call new Database(dbPath) directly, which throws when the .codegraph/ directory doesn't exist.
Suggested fix
Add the same findDbPath() check or fs.existsSync() guard before opening the database in:
cli.js cycles handler (~line 317)
cli.js export handler (~line 278)
embedder.js buildEmbeddings() (~line 327)