{"record":{"id":"f63df5e4b43644c2","repo":"chenhg5/cc-connect","slug":"project-q-located-in-parsed-config-but-not-raw-fi","errorCode":null,"errorMessage":"project %q located in parsed config but not raw file","messagePattern":"project %q located in parsed config but not raw file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/config.go","lineNumber":1240,"sourceCode":"\tif err := toml.Unmarshal(data, cfg); err != nil {\n\t\treturn fmt.Errorf(\"parse config: %w\", err)\n\t}\n\n\tprojectIdx := -1\n\tfor i := range cfg.Projects {\n\t\tif cfg.Projects[i].Name == projectName {\n\t\t\tprojectIdx = i\n\t\t\tbreak\n\t\t}\n\t}\n\tif projectIdx < 0 {\n\t\treturn fmt.Errorf(\"project %q not found in config\", projectName)\n\t}\n\n\tlines, hadTrailing := splitConfigLines(raw)\n\tspans := buildRawProjectSpans(lines)\n\tif projectIdx >= len(spans) {\n\t\treturn fmt.Errorf(\"project %q located in parsed config but not raw file\", projectName)\n\t}\n\tprojSpan := spans[projectIdx]\n\n\tfor j, prov := range cfg.Projects[projectIdx].Agent.Providers {\n\t\tif prov.Name == providerName {\n\t\t\tif j < len(projSpan.agentProviders) {\n\t\t\t\tps := projSpan.agentProviders[j]\n\t\t\t\tlines = upsertTomlStringKey(lines, ps.start+1, ps.end, \"model\", model)\n\t\t\t\treturn writeRawConfig(joinConfigLines(lines, hadTrailing))\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\tfor _, ref := range cfg.Projects[projectIdx].Agent.ProviderRefs {\n\t\tif ref == providerName {\n\t\t\treturn patchGlobalProviderField(lines, hadTrailing, cfg, providerName, \"model\", model)\n\t\t}","sourceCodeStart":1222,"sourceCodeEnd":1258,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/config/config.go#L1222-L1258","documentation":"This is an internal consistency check: the project was found in the parsed TOML (projectIdx >= 0) but buildRawProjectSpans did not produce a raw-text span at that index. Since the surgical editor needs both views to agree, it fails rather than corrupting the file.","triggerScenarios":"projectIdx >= len(spans) after buildRawProjectSpans(lines) — a mismatch between the parsed [[projects]] tables and the raw-line scanning, e.g. unusual table nesting, generated/duplicated headers, or a parser bug.","commonSituations":"Configs with non-standard [[projects]] placement or comments/formatting that confuse the raw span builder; concurrent edits rewrote the file between read and span build; a version skew where the raw-span parser lags the TOML schema.","solutions":["Report/inspect as a bug: dump the config and the wrapped error together","Simplify the [[projects]] section formatting (one standard block per project) and retry","Re-read the file — if it changed concurrently, retry the save once the writer settles","Upgrade to a version where the raw-span parser matches the TOML parser"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"lines, _ := splitConfigLines(raw)\nif projectIdx >= len(buildRawProjectSpans(lines)) {\n\treturn errors.New(\"raw/parsed mismatch; reformat [[projects]]\")\n}","typeGuard":null,"tryCatchPattern":"if err := config.SaveProviderModel(p, prov, model); err != nil {\n\tif strings.Contains(err.Error(), \"but not raw file\") {\n\t\t// fall back to full rewrite or ask user to reformat config\n\t}\n\treturn err\n}","preventionTips":["Keep [[projects]] blocks in a plain, standard shape (one table header per project)","Avoid programmatic rewrites of config with other tools while the app runs","Upgrade when the raw-span parser lags the schema; report mismatches as bugs"],"tags":["config","internal","invariant"],"backgroundTag":"internal-invariant-violation","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"}