{"record":{"id":"02a2a0d48349670f","repo":"googleapis/mcp-toolbox","slug":"error-getting-alloydb-cluster-w","errorCode":null,"errorMessage":"error getting AlloyDB cluster: %w","messagePattern":"error getting AlloyDB cluster: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/alloydbadmin/alloydbadmin.go","lineNumber":246,"sourceCode":"\tresp, err := service.Projects.Locations.Clusters.Users.Create(urlString, user).UserId(userID).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating AlloyDB user: %w\", err)\n\t}\n\n\treturn resp, nil\n}\n\nfunc (s *Source) GetCluster(ctx context.Context, project, location, cluster, accessToken string) (any, error) {\n\tservice, err := s.getService(ctx, accessToken)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\turlString := fmt.Sprintf(\"projects/%s/locations/%s/clusters/%s\", project, location, cluster)\n\n\tresp, err := service.Projects.Locations.Clusters.Get(urlString).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting AlloyDB cluster: %w\", err)\n\t}\n\n\treturn resp, nil\n}\n\nfunc (s *Source) GetInstance(ctx context.Context, project, location, cluster, instance, accessToken string) (any, error) {\n\tservice, err := s.getService(ctx, accessToken)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\turlString := fmt.Sprintf(\"projects/%s/locations/%s/clusters/%s/instances/%s\", project, location, cluster, instance)\n\n\tresp, err := service.Projects.Locations.Clusters.Instances.Get(urlString).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting AlloyDB instance: %w\", err)\n\t}\n\treturn resp, nil","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/alloydbadmin/alloydbadmin.go#L228-L264","documentation":"This error wraps a failure from the AlloyDB Admin API Clusters.Get call, which fetches a single cluster by its fully qualified resource name. It is thrown when the REST GET request fails with an HTTP error or transport failure. The wrapped error preserves the underlying Google API error for programmatic handling.","triggerScenarios":"Calling Source.GetCluster when the cluster does not exist (404), the location is wrong, the access token is expired or lacks scope, or the network request to the AlloyDB Admin endpoint fails.","commonSituations":"Querying a cluster in the wrong region, deleted clusters, misconfigured project/location strings in tool config, revoked or short-lived access tokens, and transient network failures.","solutions":["Verify the cluster name, project, and location are correct with gcloud alloydb clusters list","Check the access token is valid and has cloud-platform/alloydb scope; refresh if expired","Handle 404 distinctly — the cluster may have been deleted or never created","Retry transient failures (5xx, network errors) with backoff","Unwrap with errors.As(*googleapi.Error) to branch on the HTTP status code"],"exampleFix":"// before\nresp, err := service.Projects.Locations.Clusters.Get(urlString).Do()\nif err != nil { return nil, fmt.Errorf(\"error getting AlloyDB cluster: %w\", err) }\n// after\nresp, err := service.Projects.Locations.Clusters.Get(urlString).Do()\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) && gerr.Code == 404 {\n        return nil, fmt.Errorf(\"cluster %s not found in %s/%s: %w\", cluster, project, location, err)\n    }\n    return nil, fmt.Errorf(\"error getting AlloyDB cluster: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go: validate resource identifiers before the call\nif project == \"\" || location == \"\" || cluster == \"\" {\n    return fmt.Errorf(\"project, location and cluster must be non-empty\")\n}\nif !isValidRegion(location) {\n    return fmt.Errorf(\"location %q is not a valid AlloyDB region\", location)\n}","typeGuard":"func IsNotFound(err error) bool {\n    var gerr *googleapi.Error\n    return errors.As(err, &gerr) && gerr.Code == 404\n}","tryCatchPattern":"cluster, err := s.GetCluster(ctx, project, location, clusterName, accessToken)\nif err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) && gerr.Code == 404 {\n        return nil, fmt.Errorf(\"cluster %q does not exist in %s/%s\", clusterName, project, location)\n    }\n    if errors.As(err, &gerr) && gerr.Code >= 500 {\n        return retryWithBackoff(...)\n    }\n    return err\n}","preventionTips":["Store project/location/cluster identifiers in config and validate at startup","Check tokens' expiry and refresh proactively","Distinguish 404 from 5xx so you don't retry permanent not-found errors","Enable the AlloyDB Admin API on the project ahead of time"],"tags":["gcp","alloydb","rest-api","authorization","not-found"],"backgroundTag":"gcp-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"}