chenhg5/cc-connect · error
cc-switch database not found
Error message
cc-switch database not found
What it means
listCCSwitchProvidersForWeb reads the cc-switch SQLite database to serve the provider management API. If findCCSwitchDB() cannot locate the database file it returns this error instead of querying. It signals that cc-switch (the provider-switcher app) is not installed or its data directory is absent.
Source
Thrown at cmd/cc-connect/provider.go:492
case "linux":
dataHome := os.Getenv("XDG_DATA_HOME")
if dataHome == "" {
dataHome = filepath.Join(home, ".local", "share")
}
candidates = append(candidates, filepath.Join(dataHome, "cc-switch", "cc-switch.db"))
case "darwin":
candidates = append(candidates, filepath.Join(home, "Library", "Application Support", "cc-switch", "cc-switch.db"))
}
return candidates
}
// listCCSwitchProvidersForWeb reads the cc-switch database and returns
// providers in the format expected by the management API.
func listCCSwitchProvidersForWeb() ([]core.CCSwitchProviderInfo, error) {
dbPath := findCCSwitchDB()
if dbPath == "" {
return nil, fmt.Errorf("cc-switch database not found")
}
rows, err := queryCCSwitchDB(dbPath, "")
if err != nil {
return nil, err
}
result := make([]core.CCSwitchProviderInfo, 0, len(rows))
for _, row := range rows {
p, err := convertCCSwitchProvider(row)
if err != nil {
continue
}
result = append(result, core.CCSwitchProviderInfo{
Name: p.Name,
AppType: row.AppType,
APIKey: p.APIKey,
BaseURL: p.BaseURL,View on GitHub (pinned to 4000b2338a)
Solutions
- Install/run the cc-switch app once so it creates its database.
- Check that the database exists at the expected location (e.g. ~/.cc-switch/) and is readable by the cc-connect user.
- Run cc-connect under a user whose HOME matches the cc-switch installation, or place/copy the DB at the searched path.
Example fix
// before $ cc-connect serve # on host without cc-switch // after $ ls ~/.cc-switch/cc-switch.db # verify DB exists (install cc-switch if missing)
Defensive patterns
Strategy: fallback
Validate before calling
if _, err := os.Stat(dbPath); err != nil {
return fmt.Errorf("cc-switch database missing at %s: %w", dbPath, err)
} Type guard
if dbPath := findCCSwitchDB(); dbPath == "" { /* fall back to static provider config */ } Try / catch
rows, err := listCCSwitchProvidersForWeb()
if err != nil {
if strings.Contains(err.Error(), "database not found") {
slog.Warn("cc-switch not installed; serving empty provider list")
rows = nil
} else {
return err
}
} Prevention
- Install and launch cc-switch once before enabling provider management features.
- Ensure the cc-connect process runs as a user whose HOME contains the cc-switch DB.
- Document the expected DB path in deployment checklists.
When it happens
Trigger: Calling the web management API provider-list endpoint (or listCCSwitchProvidersForWeb directly) on a machine where no cc-switch database exists at any of the searched paths.
Common situations: cc-switch never installed; fresh machine/container without cc-switch data; cc-switch config moved to a non-default XDG/home directory; running cc-connect as a different user whose HOME doesn't contain the DB.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- open cc-switch db: %w
- query cc-switch db: %w
- invalid settings_config JSON: %w
- unsupported app_type %q (only claude and codex are supported
- no env in settings_config
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/2c5961d0e5342666.
Report an issue: GitHub.