{"record":{"id":"c13e1eec9483ba18","repo":"plandex-ai/plandex","slug":"error-checking-if-project-exists-v","errorCode":null,"errorMessage":"error checking if project exists: %v","messagePattern":"error checking if project exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/project_helpers.go","lineNumber":14,"sourceCode":"package db\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/jmoiron/sqlx\"\n)\n\nfunc ProjectExists(orgId, projectId string) (bool, error) {\n\tvar count int\n\terr := Conn.QueryRow(\"SELECT COUNT(*) FROM projects WHERE org_id = $1 AND id = $2\", orgId, projectId).Scan(&count)\n\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error checking if project exists: %v\", err)\n\t}\n\n\treturn count > 0, nil\n}\n\nfunc CreateProject(orgId, name string, tx *sqlx.Tx) (string, error) {\n\tvar projectId string\n\terr := tx.QueryRow(\"INSERT INTO projects (org_id, name) VALUES ($1, $2) RETURNING id\", orgId, name).Scan(&projectId)\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error creating project: %v\", err)\n\t}\n\n\treturn projectId, nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/project_helpers.go#L1-L30","documentation":"ProjectExists runs `SELECT COUNT(*) FROM projects WHERE org_id = $1 AND id = $2` and scans the count. A query or scan error is wrapped with this message; the boolean return only means count>0. Callers (ValidatePlanAccess, authorizeProjectOptional) use it for membership checks, so a failure here blocks authorization decisions.","triggerScenarios":"The COUNT query fails during plan access validation or optional project authorization — DB down, connection issues, or Scan failing on the QueryRow result.","commonSituations":"Transient DB outages, connection pool exhaustion under load, malformed orgId/projectId that the driver cannot bind, schema changes on the projects table.","solutions":["Inspect the wrapped inner error for the driver-level cause","Check DB connectivity and pool health","Verify orgId and projectId parameters are valid non-empty strings","Retry if the failure looks transient"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if orgId == \"\" || projectId == \"\" {\n    return errors.New(\"orgId and projectId are required\")\n}","typeGuard":null,"tryCatchPattern":"exists, err := ProjectExists(orgId, projectId)\nif err != nil {\n    // fail closed: treat as unauthorized when err != nil\n    return ErrForbidden\n}\nif !exists {\n    return ErrNotFound\n}","preventionTips":["Fail closed (deny) when the existence check errors","Index projects(org_id, id) for the COUNT query","Validate ids before querying","Add health checks/retries for transient DB issues"],"tags":["go","database","authorization","projects"],"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"}