{"record":{"id":"29e4a54269c476bd","repo":"portainer/portainer","slug":"cannot-remove-the-initial-admin-account","errorCode":null,"errorMessage":"Cannot remove the initial admin account","messagePattern":"Cannot remove the initial admin account","errorType":"http","errorClass":"httperror.HandlerError","httpStatus":403,"severity":"error","filePath":"api/http/handler/users/user_delete.go","lineNumber":39,"sourceCode":"// @tags users\n// @security ApiKeyAuth\n// @security jwt\n// @produce json\n// @param id path int true \"User identifier\"\n// @success 204 \"Success\"\n// @failure 400 \"Invalid request\"\n// @failure 403 \"Permission denied\"\n// @failure 404 \"User not found\"\n// @failure 500 \"Server error\"\n// @router /users/{id} [delete]\nfunc (handler *Handler) userDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {\n\tuserID, err := request.RetrieveNumericRouteVariableValue(r, \"id\")\n\tif err != nil {\n\t\treturn httperror.BadRequest(\"Invalid user identifier route variable\", err)\n\t}\n\n\tif userID == 1 {\n\t\treturn httperror.Forbidden(\"Cannot remove the initial admin account\", errors.New(\"Cannot remove the initial admin account\"))\n\t}\n\n\ttokenData, err := security.RetrieveTokenData(r)\n\tif err != nil {\n\t\treturn httperror.InternalServerError(\"Unable to retrieve user authentication token\", err)\n\t}\n\n\tif tokenData.ID == portainer.UserID(userID) {\n\t\treturn httperror.Forbidden(\"Cannot remove your own user account. Contact another administrator\", errAdminCannotRemoveSelf)\n\t}\n\n\tuser, err := handler.DataStore.User().Read(portainer.UserID(userID))\n\tif handler.DataStore.IsErrObjectNotFound(err) {\n\t\treturn httperror.NotFound(\"Unable to find a user with the specified identifier inside the database\", err)\n\t} else if err != nil {\n\t\treturn httperror.InternalServerError(\"Unable to find a user with the specified identifier inside the database\", err)\n\t}\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/portainer/portainer/blob/17e74456ff6e794b9d5439ec3fa06922aa18a3f8/api/http/handler/users/user_delete.go#L21-L57","documentation":"Error \"Cannot remove the initial admin account\" thrown in portainer/portainer.","triggerScenarios":"Thrown at api/http/handler/users/user_delete.go:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"17e74456ff6e794b9d5439ec3fa06922aa18a3f8","analyzedAt":"2026-08-26T23:09:01.915Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}