plandex-ai/plandex · error
error checking if project exists: %v
Error message
error checking if project exists: %v
What it means
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.
Source
Thrown at app/server/db/project_helpers.go:14
package db
import (
"fmt"
"github.com/jmoiron/sqlx"
)
func ProjectExists(orgId, projectId string) (bool, error) {
var count int
err := Conn.QueryRow("SELECT COUNT(*) FROM projects WHERE org_id = $1 AND id = $2", orgId, projectId).Scan(&count)
if err != nil {
return false, fmt.Errorf("error checking if project exists: %v", err)
}
return count > 0, nil
}
func CreateProject(orgId, name string, tx *sqlx.Tx) (string, error) {
var projectId string
err := tx.QueryRow("INSERT INTO projects (org_id, name) VALUES ($1, $2) RETURNING id", orgId, name).Scan(&projectId)
if err != nil {
return "", fmt.Errorf("error creating project: %v", err)
}
return projectId, nil
}
View on GitHub (pinned to e2d772072e)
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
Defensive patterns
Strategy: try-catch
Validate before calling
if orgId == "" || projectId == "" {
return errors.New("orgId and projectId are required")
} Try / catch
exists, err := ProjectExists(orgId, projectId)
if err != nil {
// fail closed: treat as unauthorized when err != nil
return ErrForbidden
}
if !exists {
return ErrNotFound
} Prevention
- 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
When it happens
Trigger: The COUNT query fails during plan access validation or optional project authorization — DB down, connection issues, or Scan failing on the QueryRow result.
Common situations: Transient DB outages, connection pool exhaustion under load, malformed orgId/projectId that the driver cannot bind, schema changes on the projects table.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- error validating project membership: %v
- error validating project
- error validating plan membership
- error invalidating conflicted results: %v
- error adding plan context tokens: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/c13e1eec9483ba18.
Report an issue: GitHub.