Skip to content

Commit b5ea5d7

Browse files
georgeh0claude
andcommitted
fix: gracefully handle missing index table in ccc status
When the SQLite index table hasn't been created yet, ccc status raised 'no such table: code_chunks_vec'. Now catches the OperationalError and reports 'Index not created yet' instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ae14e9a commit b5ea5d7

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/cocoindex_code/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def print_index_stats(status: ProjectStatusResponse) -> None:
100100
"""Print formatted index statistics."""
101101
if status.progress is not None:
102102
_typer.echo(f"Indexing in progress: {_format_progress(status.progress)}")
103+
if not status.index_exists:
104+
_typer.echo("\nIndex not created yet. Run `ccc index` to build the index.")
105+
return
103106
_typer.echo("\nIndex stats:")
104107
_typer.echo(f" Chunks: {status.total_chunks}")
105108
_typer.echo(f" Files: {status.total_files}")

src/cocoindex_code/daemon.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import signal
9+
import sqlite3
910
import sys
1011
import threading
1112
import time
@@ -279,15 +280,22 @@ def get_status(self, project_root: str) -> ProjectStatusResponse:
279280
)
280281

281282
db = project.env.get_context(SQLITE_DB)
282-
with db.readonly() as conn:
283-
total_chunks = conn.execute("SELECT COUNT(*) FROM code_chunks_vec").fetchone()[0]
284-
total_files = conn.execute(
285-
"SELECT COUNT(DISTINCT file_path) FROM code_chunks_vec"
286-
).fetchone()[0]
287-
lang_rows = conn.execute(
288-
"SELECT language, COUNT(*) as cnt FROM code_chunks_vec"
289-
" GROUP BY language ORDER BY cnt DESC"
290-
).fetchall()
283+
index_exists = True
284+
try:
285+
with db.readonly() as conn:
286+
total_chunks = conn.execute("SELECT COUNT(*) FROM code_chunks_vec").fetchone()[0]
287+
total_files = conn.execute(
288+
"SELECT COUNT(DISTINCT file_path) FROM code_chunks_vec"
289+
).fetchone()[0]
290+
lang_rows = conn.execute(
291+
"SELECT language, COUNT(*) as cnt FROM code_chunks_vec"
292+
" GROUP BY language ORDER BY cnt DESC"
293+
).fetchall()
294+
except sqlite3.OperationalError:
295+
index_exists = False
296+
total_chunks = 0
297+
total_files = 0
298+
lang_rows = []
291299

292300
lock = self._index_locks.get(project_root)
293301
is_indexing = lock is not None and lock.locked()
@@ -298,6 +306,7 @@ def get_status(self, project_root: str) -> ProjectStatusResponse:
298306
total_files=total_files,
299307
languages={lang: cnt for lang, cnt in lang_rows},
300308
progress=progress,
309+
index_exists=index_exists,
301310
)
302311

303312
def remove_project(self, project_root: str) -> bool:

src/cocoindex_code/protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class ProjectStatusResponse(_msgspec.Struct, tag="project_status"):
114114
total_files: int
115115
languages: dict[str, int]
116116
progress: IndexingProgress | None = None
117+
index_exists: bool = True
117118

118119

119120
class DaemonProjectInfo(_msgspec.Struct):

0 commit comments

Comments
 (0)