{"record":{"id":"5d46424efd8abf2e","repo":"plandex-ai/plandex","slug":"replacement-not-found-s","errorCode":null,"errorMessage":"replacement not found: %s","messagePattern":"replacement not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":1023,"sourceCode":"\t}\n\n\tif result.RejectedAt != nil {\n\t\treturn nil\n\t}\n\n\tnow := time.Now()\n\n\tfoundReplacement := false\n\tfor _, replacement := range result.Replacements {\n\t\tif replacement.Id == replacementId {\n\t\t\treplacement.RejectedAt = &now\n\t\t\tfoundReplacement = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif !foundReplacement {\n\t\treturn fmt.Errorf(\"replacement not found: %s\", replacementId)\n\t}\n\n\treturn nil\n}\n\nfunc GetPlanApplies(orgId, planId string) ([]*PlanApply, error) {\n\tappliesDir := getPlanAppliesDir(orgId, planId)\n\tfiles, err := os.ReadDir(appliesDir)\n\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, nil\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"error reading applies dir: %v\", err)\n\t}\n\n\tplanApplies := []*PlanApply{}","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L1005-L1041","documentation":"RejectReplacement parsed the result and scanned result.Replacements for one whose Id matches replacementId; none matched. Note the function marks replacement.RejectedAt in memory but (as written in this region) returns nil without persisting — the error is purely about lookup failure.","triggerScenarios":"Calling RejectReplacement with a replacementId that is not in the result's Replacements slice — wrong id, id from a different result, or the result has an empty Replacements list.","commonSituations":"Passing the result id as the replacement id (or vice versa); the replacement was already removed/rewritten; client cached ids from before the plan changed.","solutions":["Confirm replacementId is a member of that result's Replacements (list the result's replacements first).","Check you did not swap resultId and replacementId arguments.","Re-fetch the result to get fresh replacement ids after any plan updates."],"exampleFix":"// before\ndb.RejectReplacement(orgId, planId, resultId, replacementId)\n// after\nresult := fetchResult(resultId) // verify replacement belongs to this result\nfor _, rep := range result.Replacements {\n    if rep.Id == replacementId {\n        return db.RejectReplacement(orgId, planId, resultId, replacementId)\n    }\n}\nreturn fmt.Errorf(\"replacement %s is not on result %s\", replacementId, resultId)","handlingStrategy":"validation","validationCode":"result := getResult(resultId) // fetch and parse the result first\nvalid := false\nfor _, rep := range result.Replacements {\n    if rep.Id == replacementId {\n        valid = true\n        break\n    }\n}\nif !valid {\n    return fmt.Errorf(\"replacement %s is not on result %s\", replacementId, resultId)\n}\nreturn RejectReplacement(orgId, planId, resultId, replacementId)","typeGuard":null,"tryCatchPattern":"if err := RejectReplacement(orgId, planId, resultId, replacementId); err != nil {\n    if strings.Contains(err.Error(), \"replacement not found\") {\n        return fmt.Errorf(\"stale replacementId %s; refresh result and retry\", replacementId)\n    }\n    return err\n}","preventionTips":["Refresh replacement ids from the result right before rejecting; don't cache them across plan updates.","Don't confuse resultId and replacementId argument order.","Handle already-rewritten replacements as a normal, non-fatal case in the UI."],"tags":["go","lookup","invalid-argument"],"backgroundTag":"entity-not-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}