{"record":{"id":"b1e0bd1cf23ca4ec","repo":"plandex-ai/plandex","slug":"failed-to-load-context-v","errorCode":null,"errorMessage":"failed to load context: %v","messagePattern":"failed to load context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_auto_load.go","lineNumber":121,"sourceCode":"\t\t\t}\n\n\t\t\tmu.Lock()\n\t\t\tloadContextReqsByIndex[index] = &shared.LoadContextParams{\n\t\t\t\tContextType: contextType,\n\t\t\t\tFilePath:    path,\n\t\t\t\tName:        path,\n\t\t\t\tBody:        body,\n\t\t\t\tAutoLoaded:  true,\n\t\t\t\tImageDetail: imageDetail,\n\t\t\t}\n\t\t\tmu.Unlock()\n\t\t\terrCh <- nil\n\t\t}(i, path)\n\t}\n\n\tfor range files {\n\t\tif e := <-errCh; e != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to load context: %v\", e)\n\t\t}\n\t}\n\n\t// Convert map back to ordered slice\n\tloadContextReqs := make(shared.LoadContextRequest, 0, len(loadContextReqsByIndex))\n\tfor i := 0; i < len(files); i++ {\n\t\tif req := loadContextReqsByIndex[i]; req != nil {\n\t\t\tloadContextReqs = append(loadContextReqs, req)\n\t\t}\n\t}\n\n\t// even if there are no files to load, we still need to hit the API endpoint because the stream is waiting on a channel for the autoload to finish\n\tres, apiErr := api.Client.AutoLoadContext(ctx, CurrentPlanId, CurrentBranch, loadContextReqs)\n\tif apiErr != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load context: %v\", apiErr.Msg)\n\t}\n\n\tif res.MaxTokensExceeded {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_auto_load.go#L103-L139","documentation":"AutoLoadContextFiles drains errCh once per input file and returns this wrapper on the first non-nil error received from any per-file goroutine. It is an aggregation point: the real cause (stat failure, read failure, or a per-file processing error) is the wrapped %v value.","triggerScenarios":"Any of the N goroutines sends a non-nil error on errCh — e.g. os.Stat/os.ReadFile failures, an unsupported context type for the file extension, or size accounting failing — and the collector loop hits it before all results are processed.","commonSituations":"Batch-loading a list of context files where at least one is missing, unreadable, or of an unsupported type; large file lists increase the odds one path is stale; concurrent goroutines racing on shared map/slice state during processing.","solutions":["Unwrap the inner error to identify which file failed and why, then fix that specific path/permission.","Validate all paths exist and are readable before calling AutoLoadContextFiles.","Decide on policy: skip bad files with warnings (collect all errors, don't fail fast) for more robust loading.","Reduce the file list to known-good files when running non-interactively.","Inspect the errCh aggregation loop — because it returns on first error, remaining goroutines may still be running; ensure they are drained to avoid leaks."],"exampleFix":"// before\nfor range files {\n    if e := <-errCh; e != nil {\n        return \"\", fmt.Errorf(\"failed to load context: %v\", e)\n    }\n}\n// after\nvar errs []error\nfor range files {\n    if e := <-errCh; e != nil {\n        errs = append(errs, fmt.Errorf(\"%w\", e))\n    }\n}\nif len(errs) > 0 {\n    log.Printf(\"skipped %d context files: %v\", len(errs), errors.Join(errs...))\n}","handlingStrategy":"try-catch","validationCode":"// validate all inputs up front so goroutines never fail on obvious problems\nfor _, p := range files {\n    if p == \"\" {\n        return \"\", fmt.Errorf(\"empty path in file list\")\n    }\n    if _, err := os.Stat(expandHome(p)); err != nil {\n        log.Printf(\"warning: %s unavailable: %v\", p, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"var errs []error\nfor range files {\n    if e := <-errCh; e != nil {\n        errs = append(errs, e)\n    }\n}\nif len(errs) == len(files) {\n    return \"\", fmt.Errorf(\"failed to load context: %v\", errors.Join(errs...))\n}\nif len(errs) > 0 {\n    log.Printf(\"partial load, skipped %d files: %v\", len(errs), errors.Join(errs...))\n}","preventionTips":["Unwrap the inner error to identify the exact failing file before debugging.","Drain all goroutine errors instead of failing on the first, to avoid goroutine leaks and get full diagnostics.","Validate every path (exists, readable, regular file) before dispatching goroutines.","Decide an explicit skip-vs-fail policy for bad files based on how critical each context file is."],"tags":["concurrency","error-aggregation","filesystem","context-loading"],"backgroundTag":"context-file-load-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}