chenhg5/cc-connect · error

project %q not found in config

Error message

project %q not found in config

What it means

After parsing succeeds, SaveProviderModel searches cfg.Projects for a project matching projectName. If none matches, it returns this error — the save target simply does not exist in the config file, so nothing is written.

Source

Thrown at config/config.go:1234

	data, err := os.ReadFile(ConfigPath)
	if err != nil {
		return fmt.Errorf("read config: %w", err)
	}
	raw := string(data)
	cfg := &Config{}
	if err := toml.Unmarshal(data, cfg); err != nil {
		return fmt.Errorf("parse config: %w", err)
	}

	projectIdx := -1
	for i := range cfg.Projects {
		if cfg.Projects[i].Name == projectName {
			projectIdx = i
			break
		}
	}
	if projectIdx < 0 {
		return fmt.Errorf("project %q not found in config", projectName)
	}

	lines, hadTrailing := splitConfigLines(raw)
	spans := buildRawProjectSpans(lines)
	if projectIdx >= len(spans) {
		return fmt.Errorf("project %q located in parsed config but not raw file", projectName)
	}
	projSpan := spans[projectIdx]

	for j, prov := range cfg.Projects[projectIdx].Agent.Providers {
		if prov.Name == providerName {
			if j < len(projSpan.agentProviders) {
				ps := projSpan.agentProviders[j]
				lines = upsertTomlStringKey(lines, ps.start+1, ps.end, "model", model)
				return writeRawConfig(joinConfigLines(lines, hadTrailing))
			}
			break
		}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Run the app's project list (or grep name = under [[projects]]) and use the exact name
  2. Fix the typo in projectName at the call site
  3. Add the missing [[projects]] entry if it should exist

Example fix

// before
config.SaveProviderModel("my-project", "kimi", "m1") // actual name: "myproject"
// after
config.SaveProviderModel("myproject", "kimi", "m1")
Defensive patterns

Strategy: validation

Validate before calling

for _, pr := range cfg.Projects {
	if pr.Name == projectName { return nil }
}
return fmt.Errorf("unknown project %q", projectName)

Try / catch

if err := config.SaveProviderModel(name, prov, model); err != nil {
	if strings.Contains(err.Error(), "not found in config") {
		// list valid project names for the user
	}
	return err
}

Prevention

When it happens

Trigger: Calling SaveProviderModel with a projectName string that equals no cfg.Projects[i].Name in config.toml — misspelled name, project removed, or wrong project identifier (e.g. path vs display name).

Common situations: Scripting model switches with a stale/hard-coded project name after renaming the project; passing a directory path where only the config's project name works; project deleted by another session.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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