{"record":{"id":"065c4a724656a645","repo":"plandex-ai/plandex","slug":"error-creating-project-v-065c4a","errorCode":null,"errorMessage":"error creating project: %v","messagePattern":"error creating project: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/projects.go","lineNumber":55,"sourceCode":"\t\thttp.Error(w, \"Error parsing request body\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tif requestBody.Name == \"\" {\n\t\tlog.Println(\"Received empty name field\")\n\t\thttp.Error(w, \"name field is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tvar projectId string\n\terr = db.WithTx(r.Context(), \"create project\", func(tx *sqlx.Tx) error {\n\t\tvar err error\n\n\t\tprojectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error creating project: %v\\n\", err)\n\t\t\treturn fmt.Errorf(\"error creating project: %v\", err)\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error creating project: %v\\n\", err)\n\t\thttp.Error(w, \"Error creating project: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tresp := shared.CreateProjectResponse{\n\t\tId: projectId,\n\t}\n\n\tbytes, err := json.Marshal(resp)\n\n\tif err != nil {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/projects.go#L37-L73","documentation":"CreateProjectHandler wraps project creation in a transaction via db.WithTx; db.CreateProject inserts the new project row for the org. If the insert fails, the tx is rolled back and the error is wrapped as 'error creating project', surfacing as an HTTP 500.","triggerScenarios":"db.CreateProject fails: duplicate project name where uniqueness is enforced, FK violation on org_id, transaction deadlock or serialization failure, DB connection loss mid-tx, or empty request body Name.","commonSituations":"Duplicate-name race between two concurrent project creations; org row deleted elsewhere; Postgres deadlocks under load; DB not migrated.","solutions":["Inspect the wrapped cause: duplicate key, FK violation, or connection issue.","Check for an existing project with the same name in the org before creating.","Retry on transient errors (deadlock, serialization) with backoff.","Validate requestBody.Name is non-empty before the transaction."],"exampleFix":"// before\nprojectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)\n// after\nif strings.TrimSpace(requestBody.Name) == \"\" {\n    return fmt.Errorf(\"project name is required\")\n}\nprojectId, err = db.CreateProject(auth.OrgId, requestBody.Name, tx)","handlingStrategy":"validation","validationCode":"// Go\nname := strings.TrimSpace(requestBody.Name)\nif name == \"\" {\n    http.Error(w, \"project name is required\", http.StatusBadRequest)\n    return\n}","typeGuard":"func projectNameValid(name string) bool { return strings.TrimSpace(name) != \"\" }","tryCatchPattern":"err := db.WithTx(ctx, \"create project\", func(tx *sqlx.Tx) error {\n    projectId, err = db.CreateProject(auth.OrgId, name, tx)\n    if err != nil {\n        if isDuplicateKeyErr(err) {\n            return errProjectExists\n        }\n        return fmt.Errorf(\"error creating project: %v\", err)\n    }\n    return nil\n})","preventionTips":["Reject empty/whitespace names before the transaction.","Handle duplicate-key errors with a friendly 409 response.","Enforce unique org+name constraints at the schema level.","Retry transient tx errors (deadlock) with backoff."],"tags":["database","go","transaction"],"backgroundTag":"database-insert-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}