{"record":{"id":"6c17b583af34ebaa","repo":"plandex-ai/plandex","slug":"error-creating-plan","errorCode":null,"errorMessage":"Error creating plan: ","messagePattern":"Error creating plan: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_crud.go","lineNumber":107,"sourceCode":"\t\t\t\tlog.Printf(\"Error checking if plan exists: %v\\n\", err)\n\t\t\t\thttp.Error(w, \"Error checking if plan exists: \"+err.Error(), http.StatusInternalServerError)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif count == 0 {\n\t\t\t\tbreak\n\t\t\t}\n\n\t\t\tname = originalName + \".\" + fmt.Sprint(i)\n\t\t\ti++\n\t\t}\n\t}\n\n\tplan, err := db.CreatePlan(r.Context(), auth.OrgId, projectId, auth.User.Id, name)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error creating plan: %v\\n\", err)\n\t\thttp.Error(w, \"Error creating plan: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tresp := shared.CreatePlanResponse{\n\t\tId:   plan.Id,\n\t\tName: plan.Name,\n\t}\n\n\tbytes, err := json.Marshal(resp)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling response: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling response: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write(bytes)\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_crud.go#L89-L125","documentation":"CreatePlanHandler returns this 500 when db.CreatePlan fails to insert the new plan row. The database error text is appended to the response body. The count check succeeded but the actual INSERT/update of plan state failed.","triggerScenarios":"POST create-plan call where db.CreatePlan(r.Context(), orgId, projectId, userId, name) fails: foreign-key violation (project or user row missing), unique constraint race on the name suffix, context cancelled by the client, or DB connection loss during the write.","commonSituations":"Client disconnects mid-request cancelling the context; two concurrent creates racing past the COUNT check onto a unique index; project deleted between authorization and insert; Postgres disk full or read-only replica promoted incorrectly.","solutions":["Read the wrapped database error in the response body/server log (e.g. unique violation vs context canceled)","Retry the request if it was a transient connection error or a name-collision race (the suffix loop will pick the next name)","Verify the project still exists and the user belongs to the org before calling","Check Postgres health: disk space, connection limits, and that the transaction wasn't rolled back by serialization failure"],"exampleFix":"// before\nplan, err := db.CreatePlan(r.Context(), auth.OrgId, projectId, auth.User.Id, name)\nif err != nil { http.Error(w, \"Error creating plan: \"+err.Error(), http.StatusInternalServerError); return }\n// after\nplan, err := db.CreatePlan(r.Context(), auth.OrgId, projectId, auth.User.Id, name)\nif err != nil {\n\tif r.Context().Err() != nil { return } // client gone, don't log as server error\n\tvar pgErr *pgconn.PgError\n\tif errors.As(err, &pgErr) && pgErr.Code == \"23505\" { name = name + \".2\"; /* retry once */ }\n\t\n}","handlingStrategy":"retry","validationCode":"if r.Context().Err() != nil { return } // don't attempt insert after client cancelled","typeGuard":"func isUniqueViolation(err error) bool { var pgErr *pgconn.PgError; return errors.As(err, &pgErr) && pgErr.Code == \"23505\" }","tryCatchPattern":"plan, err := db.CreatePlan(r.Context(), orgId, projectId, userId, name)\nif err != nil {\n\tif isUniqueViolation(err) { /* retry with suffixed name */ }\n\tif isTransientDBErr(err) { /* retry with backoff */ }\n\thttp.Error(w, \"Error creating plan\", http.StatusInternalServerError)\n\treturn\n}","preventionTips":["Add a unique constraint plus retry-on-23505 to make name races deterministic","Use the request context so cancelled requests abort cleanly","Verify foreign keys (project, user) exist before insert in tests","Monitor disk space and connection saturation on the database host"],"tags":["database","insert","postgres","server-error"],"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-12T22:17:10.623Z"}