{"record":{"id":"5fa1889c76d643b6","repo":"googleapis/mcp-toolbox","slug":"error-creating-user-w","errorCode":null,"errorMessage":"error creating user: %w","messagePattern":"error creating user: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":222,"sourceCode":"\t}\n\n\tuser := sqladmin.User{\n\t\tName: name,\n\t}\n\n\tif iamUser {\n\t\tuser.Type = \"CLOUD_IAM_USER\"\n\t} else {\n\t\tuser.Type = \"BUILT_IN\"\n\t\tif password == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"missing 'password' parameter for non-IAM user\")\n\t\t}\n\t\tuser.Password = password\n\t}\n\n\tresp, err := service.Users.Insert(project, instance, &user).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating user: %w\", err)\n\t}\n\n\treturn resp, nil\n}\n\nfunc (s *Source) GetInstance(ctx context.Context, projectId, instanceId, accessToken string) (any, error) {\n\tservice, err := s.GetService(ctx, accessToken)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresp, err := service.Instances.Get(projectId, instanceId).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting instance: %w\", err)\n\t}\n\treturn resp, nil\n}\n","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L204-L240","documentation":"Thrown in CreateUsers when the sqladmin Users.Insert call (projects.instances.users.insert) fails after passing the password validation. The API rejected or failed the user-creation request.","triggerScenarios":"Calling create_user when the user already exists, the password violates the instance's password policy (Cloud SQL built-in password validation for Postgres/MySQL), the instance is not found, or IAM lacks cloudsql.users.create.","commonSituations":"Duplicate username on retry; password rejected by validate_password policy on MySQL instances; IAM principal missing roles/cloudsql.admin; host parameter conflicts on MySQL instances.","solutions":["Check whether the user already exists before inserting (idempotency).","Strengthen the password to satisfy any password validation policy on the instance.","Grant roles/cloudsql.admin to the caller.","Inspect the wrapped googleapi.Error code/message for the precise API reason (409 exists, 403 permission, 404 instance).","Confirm the instance name/project are correct and the instance is runnable."],"exampleFix":"// before: weak password rejected by policy\nUsers.Insert(project, instance, &sqladmin.User{Name: \"app\", Password: \"123\"})\n// after\nUsers.Insert(project, instance, &sqladmin.User{Name: \"app\", Password: \"Str0ng-Passw0rd!\"})","handlingStrategy":"try-catch","validationCode":"// check for existing user before insert\nexisting, err := service.Users.List(project, instance).Do()\nif err == nil {\n    for _, u := range existing.Items {\n        if u.Name == name {\n            return nil // user already exists\n        }\n    }\n}\nif len(password) < 8 {\n    return fmt.Errorf(\"password too short for typical Cloud SQL policies\")\n}","typeGuard":"func isConflict(err error) bool {\n    var gerr *googleapi.Error\n    return errors.As(err, &gerr) && gerr.Code == 409\n}","tryCatchPattern":"out, err := src.CreateUsers(ctx, project, instance, name, password, iamUser, token)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) {\n        if gerr.Code == 409 {\n            return fmt.Errorf(\"user %q already exists\", name)\n        }\n        if gerr.Code == 403 {\n            return fmt.Errorf(\"missing cloudsql.users.create permission: %w\", err)\n        }\n    }\n    return fmt.Errorf(\"create user failed: %w\", err)\n}","preventionTips":["Make user creation idempotent: list users first and skip if present.","Use passwords that satisfy the instance's password validation policy.","Grant roles/cloudsql.admin to the calling service account.","Never retry blindly on 409; treat as success or surface a clear message."],"tags":["gcp","cloud-sql","api-error","users"],"backgroundTag":"cloudsql-api-request-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}