{"record":{"id":"358a46ebd31e545e","repo":"plandex-ai/plandex","slug":"error-getting-contexts","errorCode":null,"errorMessage":"Error getting contexts: ","messagePattern":"Error getting contexts: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_context.go","lineNumber":59,"sourceCode":"\t\tBranch:   branch,\n\t\tReason:   \"list contexts\",\n\t\tScope:    db.LockScopeRead,\n\t\tCtx:      ctx,\n\t\tCancelFn: cancel,\n\t}, func(repo *db.GitRepo) error {\n\t\tres, err := db.GetPlanContexts(auth.OrgId, planId, false, false)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tdbContexts = res\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting contexts: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting contexts: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar apiContexts []*shared.Context\n\n\tfor _, dbContext := range dbContexts {\n\t\tapiContexts = append(apiContexts, dbContext.ToApi())\n\t}\n\n\tbytes, err := json.Marshal(apiContexts)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling contexts: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling contexts: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write(bytes)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L41-L77","documentation":"ListContextHandler calls db.GetPlanContexts inside db.ExecRepoOperation under a read repo lock. Any failure from the lock/repo layer or the contexts SQL query is returned to the client as HTTP 500 'Error getting contexts: <err>'.","triggerScenarios":"ExecRepoOperation fails (lock wait canceled, missing/corrupt plan git repo) or db.GetPlanContexts errors querying the contexts table for the org/plan.","commonSituations":"Database unreachable or misconfigured (bad DSN, wrong credentials); contexts table schema mismatch after version upgrade; plan repo directory missing on disk; client canceled the request while the handler waited for a lock.","solutions":["Inspect the wrapped error in the server log to identify DB vs git-repo cause","Verify PostgreSQL connectivity/credentials and that the contexts table exists with the expected schema","Retry — lock contention is transient","Check the plan's git repo directory on the server; reinitialize/restore if missing","Run any pending database migrations if the deployment was recently upgraded"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := db.Conn.Ping(); err != nil { return fmt.Errorf(\"database unreachable: %w\", err) }","typeGuard":null,"tryCatchPattern":"err := db.ExecRepoOperation(params, fn)\nif err != nil {\n\tif errors.Is(err, context.Canceled) { return } // client went away\n\thttp.Error(w, \"Error getting contexts: \"+err.Error(), http.StatusInternalServerError)\n}","preventionTips":["Keep DB credentials/DSN in env config and validate at startup","Run schema migrations on deploy to avoid column mismatches","Retry transient lock/DB errors with backoff","Ensure plan repo volumes are backed up and monitored"],"tags":["go","database","http-500","postgres"],"backgroundTag":"repo-operation-failed","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"}