Summary
WithDb() checks File.Exists for non-URI paths and catches exceptions, but doesn't validate DB schema version, integrity, or compatibility. A file.db that exists but is corrupted, empty, or from an incompatible cdidx version can reach DbContext.TryMigrateForRead() which logs errors but continues, potentially returning incorrect/partial results silently. CLI doesn't exit with a clear error if the DB is not a valid CodeIndex database.
Where
src/CodeIndex/Cli/QueryCommandRunner.cs:3117 (File.Exists check)
src/CodeIndex/Cli/QueryCommandRunner.cs:3127 (DbContext constructor no validation)
src/CodeIndex/Cli/QueryCommandRunner.cs:3128 (TryMigrateForRead swallows errors)
Suggested approach
- Add a DbContext.TryValidateIsCodeIndexDb() method that checks for required tables (codeindex_meta, symbols, references)
- Call this after DbContext construction but before DbReader creation in WithDb()
- If validation fails, print a specific error: "Error: does not appear to be a valid CodeIndex database"
- Include a hint: "Rebuild with
cdidx index <projectPath> --db <path> to create a fresh database"
- Return CommandExitCodes.DatabaseError when validation fails
- Write tests for corrupted/truncated/wrong-schema DBs
Summary
WithDb() checks File.Exists for non-URI paths and catches exceptions, but doesn't validate DB schema version, integrity, or compatibility. A file.db that exists but is corrupted, empty, or from an incompatible cdidx version can reach DbContext.TryMigrateForRead() which logs errors but continues, potentially returning incorrect/partial results silently. CLI doesn't exit with a clear error if the DB is not a valid CodeIndex database.
Where
src/CodeIndex/Cli/QueryCommandRunner.cs:3117(File.Exists check)src/CodeIndex/Cli/QueryCommandRunner.cs:3127(DbContext constructor no validation)src/CodeIndex/Cli/QueryCommandRunner.cs:3128(TryMigrateForRead swallows errors)Suggested approach
cdidx index <projectPath> --db <path>to create a fresh database"