{"record":{"id":"2e00d628ced436eb","repo":"plandex-ai/plandex","slug":"error-validating-project","errorCode":null,"errorMessage":"error validating project","messagePattern":"error validating project","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/auth_helpers.go","lineNumber":628,"sourceCode":"\n\tlog.Printf(\"UserId: %s, Email: %s, OrgId: %s\\n\", authToken.UserId, user.Email, parsed.OrgId)\n\n\treturn auth\n\n}\n\nfunc authorizeProject(w http.ResponseWriter, projectId string, auth *types.ServerAuth) bool {\n\treturn authorizeProjectOptional(w, projectId, auth, true)\n}\n\nfunc authorizeProjectOptional(w http.ResponseWriter, projectId string, auth *types.ServerAuth, shouldErr bool) bool {\n\tlog.Println(\"authorizing project\")\n\n\tprojectExists, err := db.ProjectExists(auth.OrgId, projectId)\n\n\tif err != nil {\n\t\tlog.Printf(\"error validating project: %v\\n\", err)\n\t\thttp.Error(w, \"error validating project\", http.StatusInternalServerError)\n\t\treturn false\n\t}\n\n\tif !projectExists && shouldErr {\n\t\tlog.Println(\"project does not exist in org\")\n\t\thttp.Error(w, \"project does not exist in org\", http.StatusNotFound)\n\t\treturn false\n\t}\n\n\treturn projectExists\n}\n\nfunc authorizeProjectRename(w http.ResponseWriter, projectId string, auth *types.ServerAuth) bool {\n\tif !authorizeProject(w, projectId, auth) {\n\t\treturn false\n\t}\n\n\tif !auth.HasPermission(shared.PermissionRenameAnyProject) {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/auth_helpers.go#L610-L646","documentation":"This 500 error is returned by authorizeProjectOptional when the db.ProjectExists(orgId, projectId) lookup fails with a real error (query failure, connection problem, etc.). It signals the server could not determine whether the project exists in the organization, not that the project is missing. It is a server-side infrastructure failure wrapped as an HTTP 500.","triggerScenarios":"Any handler that calls authorizeProject / ListPlansHandler / ListArchivedPlansHandler while db.ProjectExists returns a non-nil err: database connection failure, bad SQL/migration state, invalid projectId causing a query error, or DB timeout during project lookup.","commonSituations":"Postgres down or unreachable after a deploy; a malformed/non-UUID projectId string that breaks the query; connection pool exhaustion under load; schema drift where the projects table was renamed or a migration was not applied.","solutions":["Check server logs for the accompanying 'error validating project: %v' line to see the underlying database error","Verify the database is reachable and the connection pool/credentials are correct","Confirm the projectId sent by the client is well-formed (e.g., valid UUID) before hitting the API","Ensure migrations for the projects table are applied in the target environment","Retry the request once the DB issue is resolved; the error is transient when caused by connectivity"],"exampleFix":"// before (client treats any non-2xx as generic failure)\nconst res = await fetch(`/api/orgs/${orgId}/plans`);\n// after (client surfaces the specific 500 from project validation)\nconst res = await fetch(`/api/orgs/${orgId}/plans`);\nif (res.status === 500 && (await res.text()).includes('error validating project')) {\n  console.error('DB error while validating project; check server logs / retry');\n}","handlingStrategy":"retry","validationCode":"function assertValidProjectId(projectId) {\n  const uuidRe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n  if (!uuidRe.test(projectId)) throw new Error(`Malformed projectId: ${projectId}`);\n}","typeGuard":"function isProjectLookupError(res) {\n  return res.status === 500;\n}","tryCatchPattern":"try {\n  const res = await fetch(`/api/projects/${projectId}/plans`);\n  if (res.status === 500) {\n    // server-side DB failure validating the project: safe to retry after backoff\n    await sleep(1000);\n    return retryFetch();\n  }\n  return await res.json();\n} catch (e) {\n  console.error('Network failure during project authorization', e);\n  throw e;\n}","preventionTips":["Validate projectId format client-side before every request","Monitor server DB health; alert on spikes of 'error validating project' logs","Keep DB migrations applied before deploying handlers that query the projects table","Set sensible DB connection-pool limits and timeouts"],"tags":["http-500","database","authorization","go"],"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"}