{"record":{"id":"dad9dfaadac913ef","repo":"plandex-ai/plandex","slug":"error-selecting-org-org-not-found","errorCode":null,"errorMessage":"error selecting org: org not found","messagePattern":"error selecting org: org not found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/auth/org.go","lineNumber":133,"sourceCode":"\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error selecting org: %v\", err)\n\t}\n\n\tif selected == CreateOrgOption {\n\t\treturn createOrg(isLocalMode)\n\t}\n\n\tvar selectedOrg *shared.Org\n\tfor _, org := range orgs {\n\t\tif org.Name == selected {\n\t\t\tselectedOrg = org\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif selectedOrg == nil {\n\t\treturn nil, fmt.Errorf(\"error selecting org: org not found\")\n\t}\n\n\treturn selectedOrg, nil\n}\n","sourceCodeStart":115,"sourceCodeEnd":138,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/auth/org.go#L115-L138","documentation":"A consistency error in selectOrg: after the user picks an org name from the list, the code looks up the matching *shared.Org by name. If no org in the slice matches the selected string, this sentinel error is returned. It indicates the selection list and the org slice are out of sync (or the selected value is unexpected).","triggerScenarios":"selectOrg builds options from org names plus the \"Create a new org\" sentinel; if the value returned by term.SelectFromList is neither the sentinel nor matches any org.Name (e.g. duplicated org names caused a mismatch, or the list returned an unexpected value), selectedOrg stays nil.","commonSituations":"Custom or patched terminal input returning an altered string; org list mutated between rendering the list and the name lookup; whitespace/case differences in org names.","solutions":["Re-run the command so the org list and picker are rebuilt in sync","Check for duplicate org names in the account and rename one on the server","Verify no whitespace/case mangling of the selected value","Report as a bug if it reproduces consistently — the picker and lookup should always agree"],"exampleFix":"// before\nvar selectedOrg *shared.Org\nfor _, org := range orgs {\n    if org.Name == selected {\n// after (defensive: trim/normalize and select by index instead of name)\nif idx >= 0 && idx < len(orgs) {\n    selectedOrg = orgs[idx]\n}","handlingStrategy":"type-guard","validationCode":"// ensure the selected value is a known org name before lookup\nvalid := map[string]bool{}\nfor _, o := range orgs { valid[o.Name] = true }\nif !valid[selected] && selected != CreateOrgOption {\n    return fmt.Errorf(\"unexpected selection %q\", selected)\n}","typeGuard":"func orgSelected(orgs []*shared.Org, selected string) (*shared.Org, bool) {\n    for _, o := range orgs {\n        if o.Name == selected {\n            return o, true\n        }\n    }\n    return nil, false\n}","tryCatchPattern":"org, err := selectOrg(orgs, isLocalMode)\nif err != nil {\n    if strings.Contains(err.Error(), \"org not found\") {\n        // rebuild the org list and retry selection once\n    }\n    return err\n}","preventionTips":["Avoid duplicate org names in the account (rename on the server)","Don't mutate the orgs slice between listing and lookup","Re-run the command if the error appears once — it usually indicates stale state","Report persistent occurrences as a CLI bug"],"tags":["cli","org-selection","logic-error"],"backgroundTag":"org-selection-mismatch","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"}