chenhg5/cc-connect · error

invalid settings_config JSON: %w

Error message

invalid settings_config JSON: %w

What it means

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.

Source

Thrown at cmd/cc-connect/provider.go:350

		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)
	}

	p := config.ProviderConfig{
		Name: strings.ToLower(strings.ReplaceAll(strings.TrimSpace(row.Name), " ", "-")),
	}

	switch row.AppType {
	case "claude":
		return convertClaudeProvider(p, sc)
	case "codex":
		return convertCodexProvider(p, sc)
	default:
		return config.ProviderConfig{}, fmt.Errorf("unsupported app_type %q (only claude and codex are supported)", row.AppType)
	}
}

func convertClaudeProvider(p config.ProviderConfig, sc map[string]any) (config.ProviderConfig, error) {
	env, _ := sc["env"].(map[string]any)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Open the DB and inspect the row: `sqlite3 db 'SELECT settings_config FROM providers WHERE id=...'`; fix or delete the malformed row.
  2. Validate the JSON with a linter (jq) before re-inserting.
  3. Recreate the provider in the cc-switch UI so it rewrites settings_config correctly.
  4. Skip/handle malformed rows gracefully in the importer.

Example fix

// before
if err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {
    return config.ProviderConfig{}, fmt.Errorf("invalid settings_config JSON: %w", err)
}
// after
if strings.TrimSpace(row.SettingsConfig) == "" {
    return config.ProviderConfig{}, fmt.Errorf("provider %q: empty settings_config", row.Name)
}
if err := json.Unmarshal([]byte(row.SettingsConfig), &sc); err != nil {
    return config.ProviderConfig{}, fmt.Errorf("provider %q: invalid settings_config JSON: %w", row.Name, err)
}
Defensive patterns

Strategy: validation

Validate before calling

func isValidJSONObject(s string) bool {
    var m map[string]any
    return json.Unmarshal([]byte(s), &m) == nil && m != nil
}
// before import: if !isValidJSONObject(row.SettingsConfig) { skip row }

Try / catch

p, err := convertCCSwitchProvider(row)
if err != nil {
    if strings.Contains(err.Error(), "invalid settings_config JSON") {
        slog.Warn("skipping provider with corrupt settings_config", "name", row.Name)
        continue
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Hand-editing the cc-switch database and breaking JSON; importing rows from another tool with different settings format; NULL/empty settings_config values.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/0d6144de546311fe. Report an issue: GitHub.