{"record":{"id":"543bed200081c71e","repo":"googleapis/mcp-toolbox","slug":"operation-finished-with-error-s-543bed","errorCode":null,"errorMessage":"operation finished with error: %s","messagePattern":"operation finished with error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":359,"sourceCode":"}\n\nfunc (s *Source) GetWaitForOperations(ctx context.Context, service *sqladmin.Service, project, operation, connectionMessageTemplate string, delay time.Duration) (any, error) {\n\tlogger, err := util.LoggerFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\top, err := service.Operations.Get(project, operation).Do()\n\tif err != nil {\n\t\tlogger.DebugContext(ctx, fmt.Sprintf(\"error getting operation: %s, retrying in %v\", err, delay))\n\t} else {\n\t\tif op.Status == \"DONE\" {\n\t\t\tif op.Error != nil {\n\t\t\t\tvar errorBytes []byte\n\t\t\t\terrorBytes, err = json.Marshal(op.Error)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"operation finished with error but could not marshal error object: %w\", err)\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"operation finished with error: %s\", string(errorBytes))\n\t\t\t}\n\n\t\t\tvar opBytes []byte\n\t\t\topBytes, err = op.MarshalJSON()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not marshal operation: %w\", err)\n\t\t\t}\n\n\t\t\tvar data map[string]any\n\t\t\tif err := json.Unmarshal(opBytes, &data); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not unmarshal operation: %w\", err)\n\t\t\t}\n\n\t\t\tif msg, ok := generateCloudSQLConnectionMessage(ctx, s, logger, data, connectionMessageTemplate); ok {\n\t\t\t\treturn msg, nil\n\t\t\t}\n\t\t\treturn string(opBytes), nil\n\t\t}","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L341-L377","documentation":"The tracked Cloud SQL operation completed (Status == \"DONE\") but reported an error in its op.Error field. The library marshals the OperationError details into JSON and returns them as this error so the user sees why the create/update/delete failed. This is a pass-through of Google's server-side operation failure, not a client bug.","triggerScenarios":"Polling via GetWaitForOperations where service.Operations.Get returns an operation with Status \"DONE\" and op.Error != nil — e.g. instance creation failed server-side after the Insert call was accepted.","commonSituations":"Create-instance requests that passed validation but failed during provisioning: invalid tier/region combination, disk size below engine minimum, maintenance/maintenance-window conflicts, exceeded IP range in the VPC, or project quota issues discovered at provisioning time.","solutions":["Parse the JSON error payload (contains errors[].code, message) to see the exact provisioning failure","Fix the reported resource constraint (region, tier, disk size, IP range, quota) and retry the operation","Verify the target project has Cloud SQL Admin API enabled and required service accounts are healthy","Use gcloud sql operations describe <operation> for the same operation to cross-check details"],"exampleFix":"// before (caller treating generic failure)\nresult, err := src.GetWaitForOperations(ctx, service, project, opName, tpl, delay)\nif err != nil {\n    log.Fatalf(\"failed: %v\", err)\n}\n// after\nresult, err := src.GetWaitForOperations(ctx, service, project, opName, tpl, delay)\nif err != nil {\n    var opErrs struct {\n        Errors []struct{ Code, Message string } `json:\"errors\"`\n    }\n    if inner := err.Error(); strings.HasPrefix(inner, \"operation finished with error: \") {\n        _ = json.Unmarshal([]byte(strings.TrimPrefix(inner, \"operation finished with error: \")), &opErrs)\n    }\n    log.Fatalf(\"cloudsql operation failed: %+v\", opErrs.Errors)\n}","handlingStrategy":"try-catch","validationCode":"// Poll operation status and fail fast is not possible pre-call, but validate provisioning constraints first\nfunc validateProvisioning(tier, region, dbVersion, diskGB int64_name string) error {\n    minDisk := map[string]int64{\"MYSQL_8_0\": 10, \"POSTGRES_15\": 10, \"SQLSERVER_2022_STANDARD\": 20}\n    if min, ok := minDisk[dbVersion]; ok && diskGB < min {\n        return fmt.Errorf(\"disk %dGB below minimum %dGB for %s\", diskGB, min, dbVersion)\n    }\n    return nil\n}","typeGuard":"// Extract structured failure details from the error string the library returns\ntype cloudSQLOpError struct {\n    Errors []struct {\n        Code    string `json:\"code\"`\n        Message string `json:\"message\"`\n    } `json:\"errors\"`\n}\nfunc parseCloudSQLOperationError(err error) (*cloudSQLOpError, bool) {\n    const prefix = \"operation finished with error: \"\n    s := err.Error()\n    if !strings.HasPrefix(s, prefix) {\n        return nil, false\n    }\n    var ce cloudSQLOpError\n    if json.Unmarshal([]byte(strings.TrimPrefix(s, prefix)), &ce) != nil {\n        return nil, false\n    }\n    return &ce, true\n}","tryCatchPattern":"for {\n    result, err := src.GetWaitForOperations(ctx, service, project, opName, tpl, delay)\n    if err != nil {\n        if ce, ok := parseCloudSQLOperationError(err); ok {\n            for _, e := range ce.Errors {\n                log.Printf(\"provisioning failed [%s]: %s\", e.Code, e.Message)\n            }\n        }\n        return err\n    }\n    if result != nil { // DONE\n        return handleResult(result)\n    }\n    time.Sleep(delay)\n}","preventionTips":["Check that the chosen VPC IP range has enough free addresses before creating instances","Verify tier/region/dbVersion compatibility (some tiers are unavailable in some regions/versions)","Confirm Cloud SQL Admin API is enabled and project quota is sufficient before long create flows","Always poll to DONE and parse op.Error rather than assuming Insert success means provisioning success"],"tags":["gcp","cloudsql","operations","provisioning"],"backgroundTag":"cloud-operation-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"}