{"record":{"id":"2c5961d0e5342666","repo":"chenhg5/cc-connect","slug":"cc-switch-database-not-found","errorCode":null,"errorMessage":"cc-switch database not found","messagePattern":"cc-switch database not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/provider.go","lineNumber":492,"sourceCode":"\tcase \"linux\":\n\t\tdataHome := os.Getenv(\"XDG_DATA_HOME\")\n\t\tif dataHome == \"\" {\n\t\t\tdataHome = filepath.Join(home, \".local\", \"share\")\n\t\t}\n\t\tcandidates = append(candidates, filepath.Join(dataHome, \"cc-switch\", \"cc-switch.db\"))\n\tcase \"darwin\":\n\t\tcandidates = append(candidates, filepath.Join(home, \"Library\", \"Application Support\", \"cc-switch\", \"cc-switch.db\"))\n\t}\n\n\treturn candidates\n}\n\n// listCCSwitchProvidersForWeb reads the cc-switch database and returns\n// providers in the format expected by the management API.\nfunc listCCSwitchProvidersForWeb() ([]core.CCSwitchProviderInfo, error) {\n\tdbPath := findCCSwitchDB()\n\tif dbPath == \"\" {\n\t\treturn nil, fmt.Errorf(\"cc-switch database not found\")\n\t}\n\n\trows, err := queryCCSwitchDB(dbPath, \"\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresult := make([]core.CCSwitchProviderInfo, 0, len(rows))\n\tfor _, row := range rows {\n\t\tp, err := convertCCSwitchProvider(row)\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tresult = append(result, core.CCSwitchProviderInfo{\n\t\t\tName:      p.Name,\n\t\t\tAppType:   row.AppType,\n\t\t\tAPIKey:    p.APIKey,\n\t\t\tBaseURL:   p.BaseURL,","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/provider.go#L474-L510","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n$ cc-connect serve  # on host without cc-switch\n// after\n$ ls ~/.cc-switch/cc-switch.db  # verify DB exists (install cc-switch if missing)","handlingStrategy":"fallback","validationCode":"if _, err := os.Stat(dbPath); err != nil {\n    return fmt.Errorf(\"cc-switch database missing at %s: %w\", dbPath, err)\n}","typeGuard":"if dbPath := findCCSwitchDB(); dbPath == \"\" { /* fall back to static provider config */ }","tryCatchPattern":"rows, err := listCCSwitchProvidersForWeb()\nif err != nil {\n    if strings.Contains(err.Error(), \"database not found\") {\n        slog.Warn(\"cc-switch not installed; serving empty provider list\")\n        rows = nil\n    } else {\n        return err\n    }\n}","preventionTips":["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."],"tags":["go","cc-switch","database","file-not-found"],"backgroundTag":"file-not-found","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"}