{"record":{"id":"b7489a89287f57f7","repo":"chenhg5/cc-connect","slug":"open-cc-switch-db-w","errorCode":null,"errorMessage":"open cc-switch db: %w","messagePattern":"open cc-switch db: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/provider.go","lineNumber":319,"sourceCode":"\tif imported > 0 {\n\t\tfmt.Println(\"\\nActivate a provider with: /provider switch <name> in chat\")\n\t}\n}\n\ntype ccSwitchRow struct {\n\tID             string `json:\"id\"`\n\tAppType        string `json:\"app_type\"`\n\tName           string `json:\"name\"`\n\tSettingsConfig string `json:\"settings_config\"`\n\tIsCurrent      int    `json:\"is_current\"`\n}\n\n// queryCCSwitchDB opens the cc-switch SQLite database and returns provider rows.\n// appTypeFilter can be empty (return all) or \"claude\"/\"codex\".\nfunc queryCCSwitchDB(dbPath, appTypeFilter string) ([]ccSwitchRow, error) {\n\tdb, err := sql.Open(\"sqlite\", dbPath+\"?mode=ro\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"open cc-switch db: %w\", err)\n\t}\n\tdefer db.Close()\n\n\tquery := \"SELECT id, app_type, name, settings_config, is_current FROM providers\"\n\tvar args []any\n\tif appTypeFilter != \"\" {\n\t\tquery += \" WHERE app_type = ?\"\n\t\targs = append(args, appTypeFilter)\n\t}\n\n\trows, err := db.Query(query, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"query cc-switch db: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tvar result []ccSwitchRow\n\tfor rows.Next() {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/provider.go#L301-L337","documentation":"queryCCSwitchDB fails to open the cc-switch SQLite database file in read-only mode (mode=ro) and wraps the driver error with this message. sql.Open with a sqlite driver typically errors here on an invalid DSN/path or missing/unreadable file (depending on driver version), so import or listing of cc-switch providers cannot proceed.","triggerScenarios":"runProviderImport or listCCSwitchProvidersForWeb calls queryCCSwitchDB with a dbPath that does not exist, is a directory, has wrong permissions, or a malformed DSN suffix; the sqlite driver is not registered (blank import missing).","commonSituations":"cc-switch app never installed so its DB file is absent; user passed the wrong path to the cc-switch database; database located in another user's home directory without read access; forgotten `_ \"modernc.org/sqlite\"` import.","solutions":["Verify the cc-switch DB path exists: `ls -l ~/.cc-switch/...db` and correct dbPath.","Check file read permissions for the process user.","Confirm the sqlite driver is imported (blank import) so sql.Open does not fail with unknown driver.","Ensure the path contains no stray characters; the code appends `?mode=ro` so dbPath itself must be a plain file path.","If the app is not installed, install cc-switch or skip the import."],"exampleFix":"// before\ndb, err := sql.Open(\"sqlite\", dbPath+\"?mode=ro\")\n// after\nif _, err := os.Stat(dbPath); err != nil {\n    return nil, fmt.Errorf(\"cc-switch db not found at %s (is cc-switch installed?): %w\", dbPath, err)\n}\ndb, err := sql.Open(\"sqlite\", dbPath+\"?mode=ro\")","handlingStrategy":"validation","validationCode":"func ccSwitchDBReady(dbPath string) error {\n    fi, err := os.Stat(dbPath)\n    if err != nil { return fmt.Errorf(\"cc-switch db missing: %w\", err) }\n    if fi.IsDir() { return fmt.Errorf(\"%s is a directory\", dbPath) }\n    if fi.Mode().Perm()&0400 == 0 { return fmt.Errorf(\"%s not readable\", dbPath) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"rows, err := queryCCSwitchDB(dbPath, filter)\nif err != nil {\n    if strings.Contains(err.Error(), \"open cc-switch db\") {\n        return fmt.Errorf(\"cannot read cc-switch database at %s: %w (install cc-switch or fix the path)\", dbPath, err)\n    }\n    return err\n}","preventionTips":["Confirm cc-switch is installed and note its actual DB location before importing.","Test read access as the same user the daemon runs as.","Use auto-detection of the default cc-switch DB path instead of hand-typing it.","Register the sqlite driver via a blank import in the package."],"tags":["go","sqlite","database","cc-switch"],"backgroundTag":"file-open-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}