{"record":{"id":"5806e7d9d860ab91","repo":"plandex-ai/plandex","slug":"branch-not-found","errorCode":null,"errorMessage":"branch not found","messagePattern":"branch not found","errorType":"validation","errorClass":null,"httpStatus":404,"severity":"error","filePath":"app/server/db/context_helpers_update.go","lineNumber":36,"sourceCode":"\tBranchName               string\n\tContextsById             map[string]*Context\n\tSkipConflictInvalidation bool\n}\n\nfunc UpdateContexts(params UpdateContextsParams) (*shared.UpdateContextResponse, error) {\n\treq := params.Req\n\torgId := params.OrgId\n\tplan := params.Plan\n\tplanId := plan.Id\n\tbranchName := params.BranchName\n\n\tbranch, err := GetDbBranch(planId, branchName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting branch: %v\", err)\n\t}\n\n\tif branch == nil {\n\t\treturn nil, fmt.Errorf(\"branch not found\")\n\t}\n\n\ttotalTokens := branch.ContextTokens\n\ttotalPlannerTokens := totalTokens\n\n\ttotalMapTokens := 0\n\n\ttotalBasicPlannerTokens := 0\n\tfor _, context := range params.ContextsById {\n\t\tif context.ContextType != shared.ContextMapType && !context.AutoLoaded {\n\t\t\ttotalBasicPlannerTokens += context.NumTokens\n\t\t}\n\t}\n\n\tsettings, err := GetPlanSettings(plan)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting settings: %v\", err)\n\t}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/context_helpers_update.go#L18-L54","documentation":"UpdateContexts looks up the plan's branch by name with GetDbBranch(planId, branchName); this error is returned when the lookup succeeds (no error) but returns a nil branch, meaning no branch with that name exists for the plan.","triggerScenarios":"Calling UpdateContexts with a branchName that doesn't exist for the given planId — typically a deleted/renamed branch or a wrong branch name passed by the caller.","commonSituations":"The branch was deleted (e.g. after a git push/reset flow) while the client still cached its name; typo'd or case-mismatched branch name; updating contexts for a plan whose main branch was recreated under a different name.","solutions":["Re-fetch the plan's current branches and retry with a valid branch name.","Recreate the branch (or re-checkout in the client) before updating contexts.","Verify the branch name spelling/case matches what GetDbBranch stores.","Handle the nil-branch case in the caller by reloading plan state instead of reusing a cached name."],"exampleFix":"// before\nUpdateContexts(orgId, planId, \"feature-old\", req) // branch deleted\n// after\nbranches := GetDbPlanBranches(orgId, planId)\nif !contains(branches, branchName) {\n    branchName = defaultBranchFor(planId) // refresh instead of failing\n}\nUpdateContexts(orgId, planId, branchName, req)","handlingStrategy":"validation","validationCode":"branch, err := GetDbBranch(planId, branchName)\nif err != nil { return err }\nif branch == nil {\n    return fmt.Errorf(\"branch %q not found for plan %s; refresh branches first\", branchName, planId)\n}","typeGuard":"func branchExists(planId, branchName string) bool {\n    b, err := GetDbBranch(planId, branchName)\n    return err == nil && b != nil\n}","tryCatchPattern":"updated, err := UpdateContexts(orgId, planId, branchName, req)\nif err != nil && strings.Contains(err.Error(), \"branch not found\") {\n    branches, _ := GetDbPlanBranches(orgId, planId)\n    // re-resolve a valid branch and retry once\n}","preventionTips":["Re-fetch branch names from the DB instead of caching them across sessions","Normalize/validate branch name spelling and case before calling","Recreate deleted branches before issuing context updates"],"tags":["go","branch","not-found","lookup"],"backgroundTag":"resource-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"}