{"record":{"id":"0d6144de546311fe","repo":"chenhg5/cc-connect","slug":"invalid-settings-config-json-w","errorCode":null,"errorMessage":"invalid settings_config JSON: %w","messagePattern":"invalid settings_config JSON: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/provider.go","lineNumber":350,"sourceCode":"\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() {\n\t\tvar r ccSwitchRow\n\t\tif err := rows.Scan(&r.ID, &r.AppType, &r.Name, &r.SettingsConfig, &r.IsCurrent); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tresult = append(result, r)\n\t}\n\treturn result, rows.Err()\n}\n\nfunc convertCCSwitchProvider(row ccSwitchRow) (config.ProviderConfig, error) {\n\tvar sc map[string]any\n\tif err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {\n\t\treturn config.ProviderConfig{}, fmt.Errorf(\"invalid settings_config JSON: %w\", err)\n\t}\n\n\tp := config.ProviderConfig{\n\t\tName: strings.ToLower(strings.ReplaceAll(strings.TrimSpace(row.Name), \" \", \"-\")),\n\t}\n\n\tswitch row.AppType {\n\tcase \"claude\":\n\t\treturn convertClaudeProvider(p, sc)\n\tcase \"codex\":\n\t\treturn convertCodexProvider(p, sc)\n\tdefault:\n\t\treturn config.ProviderConfig{}, fmt.Errorf(\"unsupported app_type %q (only claude and codex are supported)\", row.AppType)\n\t}\n}\n\nfunc convertClaudeProvider(p config.ProviderConfig, sc map[string]any) (config.ProviderConfig, error) {\n\tenv, _ := sc[\"env\"].(map[string]any)","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/provider.go#L332-L368","documentation":"convertCCSwitchProvider unmarshals the row's settings_config column (expected to be a JSON object) into a map; when the column content is not valid JSON this error is returned. It means a cc-switch provider row is present but its serialized settings payload is corrupt or in an unexpected format, so the provider cannot be converted into a config.ProviderConfig.","triggerScenarios":"A providers row has settings_config that is empty, truncated, single-quoted, or otherwise not valid JSON — e.g. manually edited DB rows, or a cc-switch version storing a different serialization.","commonSituations":"Hand-editing the cc-switch database and breaking JSON; importing rows from another tool with different settings format; NULL/empty settings_config values.","solutions":["Open the DB and inspect the row: `sqlite3 db 'SELECT settings_config FROM providers WHERE id=...'`; fix or delete the malformed row.","Validate the JSON with a linter (jq) before re-inserting.","Recreate the provider in the cc-switch UI so it rewrites settings_config correctly.","Skip/handle malformed rows gracefully in the importer."],"exampleFix":"// before\nif err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {\n    return config.ProviderConfig{}, fmt.Errorf(\"invalid settings_config JSON: %w\", err)\n}\n// after\nif strings.TrimSpace(row.SettingsConfig) == \"\" {\n    return config.ProviderConfig{}, fmt.Errorf(\"provider %q: empty settings_config\", row.Name)\n}\nif err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {\n    return config.ProviderConfig{}, fmt.Errorf(\"provider %q: invalid settings_config JSON: %w\", row.Name, err)\n}","handlingStrategy":"validation","validationCode":"func isValidJSONObject(s string) bool {\n    var m map[string]any\n    return json.Unmarshal([]byte(s), &m) == nil && m != nil\n}\n// before import: if !isValidJSONObject(row.SettingsConfig) { skip row }","typeGuard":null,"tryCatchPattern":"p, err := convertCCSwitchProvider(row)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid settings_config JSON\") {\n        slog.Warn(\"skipping provider with corrupt settings_config\", \"name\", row.Name)\n        continue\n    }\n    return err\n}","preventionTips":["Never hand-edit settings_config; use the cc-switch UI.","Validate JSON with jq after any manual DB surgery.","Skip-and-log malformed rows instead of aborting the whole import.","Export/import via cc-switch's own mechanism when migrating data."],"tags":["go","json","cc-switch","import"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}