{"record":{"id":"ade02a547dab2155","repo":"plandex-ai/plandex","slug":"error-listing-projects","errorCode":null,"errorMessage":"Error listing projects: ","messagePattern":"Error listing projects: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/projects.go","lineNumber":96,"sourceCode":"\n\tw.Write(bytes)\n\n\tlog.Println(\"Successfully created project\", projectId)\n}\n\nfunc ListProjectsHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for ListProjectsHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\trows, err := db.Conn.Query(\"SELECT id, name FROM projects WHERE org_id = $1\", auth.OrgId)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error listing projects: %v\\n\", err)\n\t\thttp.Error(w, \"Error listing projects: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar projects []shared.Project\n\n\tfor rows.Next() {\n\t\tvar project shared.Project\n\t\terr := rows.Scan(&project.Id, &project.Name)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error scanning project: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error scanning project: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\tprojects = append(projects, project)\n\t}\n\n\tbytes, err := json.Marshal(projects)\n\tif err != nil {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/projects.go#L78-L114","documentation":"ListProjectsHandler issues 'SELECT id, name FROM projects WHERE org_id = $1' against the shared db.Conn. Any error returned by database/sql Query — connection failure, bad SQL, missing table — is logged and returned as HTTP 500 with the driver's error text appended.","triggerScenarios":"GET/POST to the list-projects endpoint after successful auth, when the DB query fails: Postgres unreachable, connection pool exhausted, projects table missing, or syntax/permission error on the query.","commonSituations":"Postgres down or restarted; wrong DATABASE_URL in server env; migrations not applied; too many open connections (max_connections exceeded); TLS/cert misconfiguration between server and DB.","solutions":["Read the appended driver error: 'connection refused' means DB is down/wrong host; 'relation \"projects\" does not exist' means run migrations.","Verify Postgres is running and reachable from the server (psql with the same DSN).","Check env/DSN configuration (host, port, user, password, dbname) for typos.","Ensure migrations creating the projects table have been applied.","If pool exhaustion, raise max_connections or fix leaked rows (note: this handler never calls rows.Close(), which can leak connections under load)."],"exampleFix":"// before\nrows, err := db.Conn.Query(\"SELECT id, name FROM projects WHERE org_id = $1\", auth.OrgId)\n...\n// after\nrows, err := db.Conn.Query(\"SELECT id, name FROM projects WHERE org_id = $1\", auth.OrgId)\nif err != nil { ... }\ndefer rows.Close()","handlingStrategy":"retry","validationCode":"if err := db.Conn.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"projects, err := client.ListProjects(ctx)\nif err != nil {\n\tvar apiErr *APIError\n\tif errors.As(err, &apiErr) && apiErr.StatusCode == 500 {\n\t\treturn retryWithBackoff(ctx, 3, func() error { _, err = client.ListProjects(ctx); return err })\n\t}\n\treturn err\n}","preventionTips":["Add readiness/liveness probes that ping the database before serving traffic.","Apply migrations as part of deployment before the server starts.","Pool connections properly (always defer rows.Close()) to avoid exhaustion.","Alert on DB error rates; distinguish connection-refused from SQL errors in logs.","Use a DSN from env with validated defaults and connection timeout settings."],"tags":["database","postgres","sql","http-500","connection"],"backgroundTag":"database-query-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"}