googleapis/mcp-toolbox · error
error getting AlloyDB instance: %w
Error message
error getting AlloyDB instance: %w
What it means
This error wraps a failure from the AlloyDB Admin API Instances.Get call, which fetches a single instance under a cluster via its resource path projects/*/locations/*/clusters/*/instances/*. It indicates the REST GET request failed — typically 404, 403, or a transport error. The original API error is wrapped with %w for inspection.
Source
Thrown at internal/sources/alloydbadmin/alloydbadmin.go:262
resp, err := service.Projects.Locations.Clusters.Get(urlString).Do()
if err != nil {
return nil, fmt.Errorf("error getting AlloyDB cluster: %w", err)
}
return resp, nil
}
func (s *Source) GetInstance(ctx context.Context, project, location, cluster, instance, accessToken string) (any, error) {
service, err := s.getService(ctx, accessToken)
if err != nil {
return nil, err
}
urlString := fmt.Sprintf("projects/%s/locations/%s/clusters/%s/instances/%s", project, location, cluster, instance)
resp, err := service.Projects.Locations.Clusters.Instances.Get(urlString).Do()
if err != nil {
return nil, fmt.Errorf("error getting AlloyDB instance: %w", err)
}
return resp, nil
}
func (s *Source) GetUsers(ctx context.Context, project, location, cluster, user, accessToken string) (any, error) {
service, err := s.getService(ctx, accessToken)
if err != nil {
return nil, err
}
urlString := fmt.Sprintf("projects/%s/locations/%s/clusters/%s/users/%s", project, location, cluster, user)
resp, err := service.Projects.Locations.Clusters.Users.Get(urlString).Do()
if err != nil {
return nil, fmt.Errorf("error getting AlloyDB user: %w", err)
}
return resp, nil
}View on GitHub (pinned to 8cc6e09de2)
Solutions
- Confirm the instance exists under the cluster (ListInstance or gcloud alloydb instances list)
- Verify project/location/cluster/instance IDs are exact and correctly ordered in the resource path
- Refresh the access token and check it carries cloud-platform or alloydb.admin scope
- Wait for instance creation operations to complete before calling GetInstance
- Use errors.As(*googleapi.Error) to distinguish 404 from 403/5xx and act accordingly
Example fix
// before
resp, err := service.Projects.Locations.Clusters.Instances.Get(urlString).Do()
if err != nil { return nil, fmt.Errorf("error getting AlloyDB instance: %w", err) }
// after
resp, err := service.Projects.Locations.Clusters.Instances.Get(urlString).Do()
if err != nil {
var gerr *googleapi.Error
if errors.As(err, &gerr) && gerr.Code == 404 {
return nil, fmt.Errorf("instance %s not found in cluster %s: %w", instance, cluster, err)
}
return nil, fmt.Errorf("error getting AlloyDB instance: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go: confirm the parent cluster (and thus instance path) before GetInstance
if instance == "" {
return fmt.Errorf("instance name is required")
}
if _, err := s.GetCluster(ctx, project, location, cluster, accessToken); err != nil {
return fmt.Errorf("cluster %s not found; cannot get instance %s: %w", cluster, instance, err)
} Type guard
func IsNotFound(err error) bool {
var gerr *googleapi.Error
return errors.As(err, &gerr) && gerr.Code == 404
} Try / catch
inst, err := s.GetInstance(ctx, project, location, cluster, instance, accessToken)
if err != nil {
var gerr *googleapi.Error
if errors.As(err, &gerr) && gerr.Code == 404 {
return nil, nil // treat as absent, not fatal
}
return nil, err
} Prevention
- Only query instances after their create operation reports Done
- Validate the full resource path components before the call
- Refresh tokens in long-running pollers
- Handle 404 as 'absent' rather than retrying
When it happens
Trigger: Calling Source.GetInstance with an instance ID that does not exist in the cluster, wrong cluster/location in the path, an access token lacking the required scope, or a network failure during the .Do() call.
Common situations: Instance already deleted, typos in instance or cluster names, querying before the create operation finished, expired tokens in long-lived server processes, and regional endpoint misconfiguration.
Related errors
- error getting AlloyDB cluster: %w
- error getting AlloyDB user: %w
- error creating AlloyDB instance: %w
- error creating AlloyDB user: %w
- error listing AlloyDB clusters: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/3836bea0e97fe1b9.
Report an issue: GitHub.