{"record":{"id":"749bc50a9f8478a9","repo":"googleapis/mcp-toolbox","slug":"error-cloning-instance-w","errorCode":null,"errorMessage":"error cloning instance: %w","messagePattern":"error cloning instance: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":176,"sourceCode":"\t\tcloneContext.PointInTime = pointInTime\n\t}\n\tif preferredZone != \"\" {\n\t\tcloneContext.PreferredZone = preferredZone\n\t}\n\tif preferredSecondaryZone != \"\" {\n\t\tcloneContext.PreferredSecondaryZone = preferredSecondaryZone\n\t}\n\n\trb := &sqladmin.InstancesCloneRequest{\n\t\tCloneContext: cloneContext,\n\t}\n\tservice, err := s.GetService(ctx, accessToken)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tresp, err := service.Instances.Clone(project, sourceInstanceName, rb).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error cloning instance: %w\", err)\n\t}\n\treturn resp, nil\n}\n\nfunc (s *Source) CreateDatabase(ctx context.Context, name, project, instance, accessToken string) (any, error) {\n\tdatabase := sqladmin.Database{\n\t\tName:     name,\n\t\tProject:  project,\n\t\tInstance: instance,\n\t}\n\n\tservice, err := s.GetService(ctx, accessToken)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresp, err := service.Databases.Insert(project, instance, &database).Do()\n\tif err != nil {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L158-L194","documentation":"Thrown in CloneInstance when the sqladmin Instances.Clone call (projects.instances.clone) returns an API error. The clone request reached Cloud SQL (or failed client-side) and the API rejected or failed the operation.","triggerScenarios":"Calling the clone_instance tool when the source instance does not exist, the target/override settings are invalid (e.g. same-region violation, point-in-time timestamp malformed), the project lacks the sql.instances.clone permission, or quota/billing blocks instance creation.","commonSituations":"Cloning into a project where the Cloud SQL Admin API is not enabled; cloning a source instance that is currently under maintenance or has PITR disabled while supplying a point-in-time; IAM principal missing roles/cloudsql.admin.","solutions":["Confirm the source instance name and project are correct and the instance is RUNNABLE.","Grant the caller IAM role roles/cloudsql.admin (or sql.instances.clone) in the target project.","Enable the sqladmin.googleapis.com API in the project.","If using point-in-time recovery, ensure binary logging is enabled on the source and the timestamp is within the recovery window and RFC3339-formatted.","Inspect the wrapped googleapi.Error for its code and message to pinpoint the API rejection reason."],"exampleFix":"// before: PITR timestamp without binary logging\nCloneReq{PointInTime: \"2024-01-01T00:00:00Z\"}\n// after: enable binary logging on source first, or omit PointInTime for a current-state clone\nCloneReq{} // plain clone","handlingStrategy":"try-catch","validationCode":"// pre-check source instance exists and is runnable\nresp, err := src.GetInstance(ctx, project, sourceInstanceName, accessToken)\nif err != nil {\n    return fmt.Errorf(\"cannot clone: source instance unavailable: %w\", err)\n}\ninst := resp.(*sqladmin.Operation) // preceding get ensures project/instance are valid","typeGuard":"func isNotFound(err error) bool {\n    var gerr *googleapi.Error\n    return errors.As(err, &gerr) && gerr.Code == 404\n}","tryCatchPattern":"out, err := src.CloneInstance(ctx, project, source, rb, token)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) {\n        switch gerr.Code {\n        case 403:\n            return fmt.Errorf(\"missing cloudsql.instances.clone permission: %w\", err)\n        case 404:\n            return fmt.Errorf(\"source instance not found: %w\", err)\n        }\n    }\n    return fmt.Errorf(\"clone failed: %w\", err)\n}\n// Clone returns an Operation; poll it before assuming success","preventionTips":["Verify the source instance exists and is RUNNABLE before cloning.","Enable binary logging for point-in-time clones and keep timestamps within the PITR window.","Grant roles/cloudsql.admin in the target project.","Poll the returned Operation and handle long-running clone completion."],"tags":["gcp","cloud-sql","api-error","clone"],"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"}