Skip to content

fix(cli): report daemon errors from ccc search without a traceback - #335

Open
hatemadi15 wants to merge 1 commit into
cocoindex-io:mainfrom
hatemadi15:fix/search-daemon-error-message
Open

hatemadi15 wants to merge 1 commit into
cocoindex-io:mainfrom
hatemadi15:fix/search-daemon-error-message

Conversation

@hatemadi15

Copy link
Copy Markdown

When the daemon reports an error, ccc search and ccc status die with an unhandled RuntimeError and a Rich traceback of client frames, while ccc index prints Indexing failed: <error> and exits 1.

Change

  • ccc search catches the error around the request, the way _run_index_with_progress does for ccc index, and turns it into an unsuccessful SearchResponse.
    • Text mode prints it through the existing Search failed: <error> branch of print_search_results. That branch was unreachable before (the daemon reports failures as ErrorResponse, never as success=False), and it now exits 1.
    • --json keeps the contract from feat(cli): add --json flag to ccc search #216: the failure goes to stdout as JSON ("success": false plus "message") and the command exits 1. Before this change it printed a traceback and nothing on stdout.
  • ccc status, and the status request ccc index makes after indexing, go through one helper. It prints Failed to get project status: <error> and exits 1.
  • DaemonStartError still propagates to _catch_daemon_start_error in all three.

The other daemon-facing commands already handle this:

  • init (model check), doctor and reset catch the error.
  • mcp returns it as a failed result.
  • The daemon status handler only reads in-memory daemon state and loads no project, so there is no daemon-side failure for it to report.
  • daemon restart and daemon stop are daemon lifecycle and are unchanged.

As with ccc index, the message still ends with the daemon-side traceback that _daemon_error appends (#270).

Validation

I ran the real CLI against a real daemon, with LiteLLM pointed at a local fake OpenAI embeddings endpoint and a throwaway HOME and COCOINDEX_CODE_DIR. Two daemon-side failures:

  • A: stop the endpoint after a successful init and index, so the query embedding fails.
  • B: write an unparsable .cocoindex_code/settings.yml and stop the daemon, so the fresh daemon fails to load the project.
command main this branch
A ccc search add two numbers Rich traceback ending in RuntimeError: Daemon error: litellm.InternalServerError: ... Connection error., exit 1 Search failed: Daemon error: litellm.InternalServerError: ... Connection error. and the daemon traceback, exit 1
A ccc search add two numbers --json same traceback, empty stdout, exit 1 stdout {"type":"search","success":false,"results":[],"total_returned":0,"offset":0,"message":"Daemon error: litellm.InternalServerError: ..."}, exit 1
B ccc index Indexing failed: Daemon error: Error loading .../settings.yml: while parsing a flow sequence ..., exit 1 unchanged
B ccc search add two numbers Rich traceback ending in RuntimeError: Daemon error: Error loading .../settings.yml: ..., exit 1 Search failed: Daemon error: Error loading .../settings.yml: ..., exit 1
B ccc search add two numbers --json same traceback, empty stdout, exit 1 stdout JSON with "success":false and the message, exit 1
B ccc status project/settings lines, then a Rich traceback, exit 1 project/settings lines, then Failed to get project status: Daemon error: Error loading .../settings.yml: ..., exit 1

A successful ccc search against the same project is unchanged: one result, exit 0.

  • The new test_session_search_and_status_report_daemon_errors in tests/test_e2e.py runs scenario B through CliRunner against a real daemon (index, search, search --json, status). With cli.py reverted it fails (1 failed): RuntimeError: Daemon error: Error loading ... escapes ccc search. With the fix it passes.
  • uv run prek run --all-files passes, including its uv run pytest tests/ -v hook: 351 passed, 8 deselected. That is main's 350 plus the new test.
  • uv run ruff check ., uv run ruff format --check . and uv run mypy src/ tests/ pass. uv run mypy . reports 2 errors in scripts/find_best_models.py, which main reports too.

@hatemadi15
hatemadi15 marked this pull request as ready for review November 9, 2026 19:42

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant