chenhg5/cc-connect · error
query cc-switch db: %w
Error message
query cc-switch db: %w
What it means
The SQL SELECT against the cc-switch providers table returned an error from db.Query. This indicates the query could not be executed — typically a schema mismatch (no `providers` table or missing columns like settings_config/is_current) or the database is locked/corrupt.
Source
Thrown at cmd/cc-connect/provider.go:332
// queryCCSwitchDB opens the cc-switch SQLite database and returns provider rows.
// appTypeFilter can be empty (return all) or "claude"/"codex".
func queryCCSwitchDB(dbPath, appTypeFilter string) ([]ccSwitchRow, error) {
db, err := sql.Open("sqlite", dbPath+"?mode=ro")
if err != nil {
return nil, fmt.Errorf("open cc-switch db: %w", err)
}
defer db.Close()
query := "SELECT id, app_type, name, settings_config, is_current FROM providers"
var args []any
if appTypeFilter != "" {
query += " WHERE app_type = ?"
args = append(args, appTypeFilter)
}
rows, err := db.Query(query, args...)
if err != nil {
return nil, fmt.Errorf("query cc-switch db: %w", err)
}
defer rows.Close()
var result []ccSwitchRow
for rows.Next() {
var r ccSwitchRow
if err := rows.Scan(&r.ID, &r.AppType, &r.Name, &r.SettingsConfig, &r.IsCurrent); err != nil {
continue
}
result = append(result, r)
}
return result, rows.Err()
}
func convertCCSwitchProvider(row ccSwitchRow) (config.ProviderConfig, error) {
var sc map[string]any
if err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {
return config.ProviderConfig{}, fmt.Errorf("invalid settings_config JSON: %w", err)View on GitHub (pinned to 4000b2338a)
Solutions
- Confirm dbPath points to the actual cc-switch database containing a `providers` table (`sqlite3 file .tables`).
- Check the table has columns id, app_type, name, settings_config, is_current; migrate or update cc-switch if the schema differs.
- Retry if the DB was temporarily locked by another process.
- Inspect the unwrapped sqlite error for `no such table`/`database is locked` hints.
Example fix
// before
rows, err := db.Query(query, args...)
if err != nil {
return nil, fmt.Errorf("query cc-switch db: %w", err)
}
// after
rows, err := db.Query(query, args...)
if err != nil {
if strings.Contains(err.Error(), "no such table") {
return nil, fmt.Errorf("query cc-switch db: %s does not look like a cc-switch database: %w", dbPath, err)
}
return nil, fmt.Errorf("query cc-switch db: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
db, err := sql.Open("sqlite", dbPath+"?mode=ro")
if err != nil { return err }
var n int
if err := db.QueryRow("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='providers'").Scan(&n); err != nil || n == 0 {
return fmt.Errorf("%s has no providers table (not a cc-switch db?)", dbPath)
} Try / catch
rows, err := queryCCSwitchDB(dbPath, filter)
if err != nil {
var qErr error
if strings.Contains(err.Error(), "query cc-switch db") { qErr = err }
slog.Error("cc-switch query failed", "db", dbPath, "err", qErr)
return fmt.Errorf("query cc-switch db: %w", err)
}
defer rows.Close() // always close on success path too Prevention
- Verify the schema with `sqlite3 <db> '.schema providers'` before importing.
- Ensure no other process holds a write lock on the DB during import.
- Point at the genuine cc-switch database file, not another sqlite file.
- Keep cc-switch updated so schema stays compatible.
When it happens
Trigger: queryCCSwitchDB executes `SELECT id, app_type, name, settings_config, is_current FROM providers [WHERE app_type = ?]` and the sqlite driver returns an error — older cc-switch schema without those columns, wrong file passed (not a cc-switch DB), or locked database.
Common situations: Pointing dbPath at a different sqlite file that has no providers table; cc-switch upgraded/downgraded changing the schema; concurrent access locking the DB; corrupted sqlite file.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- open cc-switch db: %w
- cc-switch database not found
- listen for Agy permission hooks: %w
- generate permission bridge token: %w
- resolve home directory for Agy permission bridge: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/0b70b70ed35ac12d.
Report an issue: GitHub.