Skip to content

Commit 35ca306

Browse files
committed
fix: ccs search crash on no-flag queries and empty results
Fixed unbound variable error (args[@] with set -u) when running ccs with a query but no flags like -d or -p. Added prerequisite checks: warns if cc-conversation-search missing, auto-initializes index if missing. Improved zero-results handling to show a clean message instead of a Python traceback.
1 parent e2759ef commit 35ca306

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

bin/ccs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,18 @@ print()
412412
esac
413413
done
414414

415+
# Check prerequisites
416+
if ! command -v cc-conversation-search &>/dev/null; then
417+
echo "cc-conversation-search not installed. Run: ccs update"
418+
exit 1
419+
fi
420+
if [ ! -f "${HOME}/.conversation-search/index.db" ]; then
421+
echo "No search index. Building it now..."
422+
cc-conversation-search init 2>&1 | tail -3
423+
fi
424+
415425
# Run search in JSON mode to extract session IDs
416-
json_output=$(cc-conversation-search search "$query" --json --limit "${limit:-10}" "${args[@]}" 2>&1)
426+
json_output=$(cc-conversation-search search "$query" --json --limit "${limit:-10}" ${args[@]+"${args[@]}"} 2>&1)
417427

418428
# Parse unique sessions and cache them
419429
if command -v python3 &>/dev/null; then
@@ -423,8 +433,11 @@ from collections import OrderedDict
423433
424434
try:
425435
results = json.load(sys.stdin)
426-
except:
427-
print('No results found.', file=sys.stderr)
436+
except (json.JSONDecodeError, ValueError):
437+
results = []
438+
439+
if not results:
440+
print('No sessions found for that query.')
428441
sys.exit(0)
429442
430443
# Deduplicate by session_id, preserve order
@@ -458,7 +471,7 @@ if total > 0:
458471
" 2>&1
459472
else
460473
# Fallback: just run normal search (no numbering)
461-
cc-conversation-search search "$query" "${args[@]}"
474+
cc-conversation-search search "$query" ${args[@]+"${args[@]}"}
462475
fi
463476
;;
464477
esac

0 commit comments

Comments
 (0)