{"record":{"id":"5da09c0303681955","repo":"plandex-ai/plandex","slug":"error-deleting-pending-results-v","errorCode":null,"errorMessage":"error deleting pending results: %v","messagePattern":"error deleting pending results: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":899,"sourceCode":"\t\t\tif result.ToApi().IsPending() && paths[result.Path] {\n\t\t\t\tlog.Printf(\"Deleting pending result: %s\", resultId)\n\n\t\t\t\terr = os.Remove(filepath.Join(resultsDir, resultId+\".json\"))\n\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- fmt.Errorf(\"error deleting result file: %v\", err)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\terrCh <- nil\n\t\t}(resultId)\n\t}\n\n\tfor i := 0; i < len(files); i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error deleting pending results: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc RejectPlanFiles(orgId, planId string, files []string, now time.Time) error {\n\terrCh := make(chan error, len(files))\n\n\tfor _, file := range files {\n\t\tgo func(file string) {\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in RejectPlanFiles: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in RejectPlanFiles: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}\n\t\t\t}()","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L881-L917","documentation":"DeletePendingResultsForPaths collects one error per goroutine from errCh and wraps the first failure as 'error deleting pending results: %v'. Any per-file failure (read, unmarshal, delete, or panic) surfaces here as the aggregate error returned to the caller.","triggerScenarios":"Any goroutine in the sweep fails: result file unreadable, unparseable JSON, os.Remove failure, or a recovered panic in a worker goroutine.","commonSituations":"Corrupt or foreign files in the results dir; permission problems on the results directory; race with another process deleting files concurrently.","solutions":["Inspect the wrapped %v to identify the per-file root cause (read/unmarshal/delete/panic)","Clean or repair the offending result file or fix directory permissions","Harden per-file handling so transient issues are logged and skipped rather than failing the sweep","Restrict mutation of the results directory to this code path to avoid races"],"exampleFix":"// before\nerr := <-errCh\nif err != nil {\n    return fmt.Errorf(\"error deleting pending results: %v\", err)\n}\n// after\nerr := <-errCh\nif err != nil {\n    log.Printf(\"pending-result cleanup error (continuing): %v\", err)\n    lastErr = err\n}\n// return lastErr at end if policy requires","handlingStrategy":"try-catch","validationCode":"entries, err := os.ReadDir(getPlanResultsDir(orgId, planId))\nif err != nil && !os.IsNotExist(err) {\n    return fmt.Errorf(\"cannot read results dir: %v\", err)\n}\nfor _, e := range entries {\n    b, _ := os.ReadFile(filepath.Join(resultsDir, e.Name()))\n    if !json.Valid(b) { log.Printf(\"corrupt result file: %s\", e.Name()) }\n}","typeGuard":null,"tryCatchPattern":"if err := DeletePendingResultsForPaths(orgId, planId, paths); err != nil {\n    log.Printf(\"deleting pending results failed: %v\", err)\n    // unwrap: errors like 'error unmarshalling result file' point to corrupt data\n}","preventionTips":["Pre-clean corrupt/unparseable files before running the deletion sweep","Avoid running concurrent cleanups on the same plan","Log per-file errors and continue rather than failing the entire batch","Use atomic writes when generating result files"],"tags":["go","error-wrapping","concurrency","filesystem","cleanup"],"backgroundTag":"batch-cleanup-partial-failure","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}