{"record":{"id":"22424941a8509d2f","repo":"googleapis/mcp-toolbox","slug":"failed-to-search-for-vm-w","errorCode":null,"errorMessage":"failed to search for VM: %w","messagePattern":"failed to search for VM: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/cloudsqlconnect/gce.go","lineNumber":183,"sourceCode":"\t// quotes for GCE's filter language regardless.\n\treq := service.Instances.AggregatedList(project).Filter(fmt.Sprintf(\"name eq %q\", vmName))\n\terr := req.Pages(ctx, func(page *compute.InstanceAggregatedList) error {\n\t\tfor zone, list := range page.Items {\n\t\t\tfor _, instance := range list.Instances {\n\t\t\t\tif instance.Name != vmName {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfoundInstances = append(foundInstances, instance)\n\t\t\t\tfoundZones = append(foundZones, ExtractNetworkName(zone))\n\t\t\t\tif len(foundInstances) > 1 {\n\t\t\t\t\treturn stopPaging\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t})\n\tif err != nil && err != stopPaging {\n\t\treturn nil, \"\", fmt.Errorf(\"failed to search for VM: %w\", err)\n\t}\n\n\tswitch len(foundInstances) {\n\tcase 0:\n\t\treturn nil, \"\", fmt.Errorf(\"VM %q not found in project %q\", vmName, project)\n\tcase 1:\n\t\treturn foundInstances[0], foundZones[0], nil\n\tdefault:\n\t\treturn nil, \"\", fmt.Errorf(\"multiple VMs named %q found in zones: %v - please specify vm_zone parameter\", vmName, foundZones)\n\t}\n}\n\n// stringErr signals early termination from Pages without conflating with\n// real API errors. Unexported: only FindVM's Pages callback uses it.\ntype stringErr string\n\nfunc (e stringErr) Error() string { return string(e) }\n","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/cloudsqlconnect/gce.go#L165-L201","documentation":"FindVM pages through Compute Engine's AggregatedList of instances to locate a VM by name in a project. Any API error encountered during paging (other than the internal stopPaging sentinel) is wrapped in this error, distinct from the separate 'VM not found' case.","triggerScenarios":"The compute Service.AggregatedList call fails during iteration — quota exceeded, permission denied (missing compute.instances.list), invalid project ID, disabled Compute Engine API, or transient 5xx/network errors.","commonSituations":"Service account lacking compute.viewer on the project; wrong project ID in the connection name; Compute Engine API disabled; GKE/regional quota exhaustion; flaky network between the VM and googleapis.","solutions":["Grant the caller service account compute.instances.list permission (roles/compute.viewer) on the target project","Verify the project ID is correct and the Compute Engine API is enabled","Inspect the wrapped %w error for the underlying Google API status and retry on transient 5xx","Check quotas and network connectivity/proxy settings to compute.googleapis.com"],"exampleFix":"// before\nsvc, err := cloudsqlconnect.GetComputeService(ctx, token) // token lacks compute scopes\nvm, zone, err := cloudsqlconnect.FindVM(ctx, svc, project, vmName)\n// after\n// ensure token includes compute.readonly scope, then retry on transient errors\nvar vm *compute.Instance\nvar zone string\nfor attempt := 0; attempt < 3; attempt++ {\n    vm, zone, err = cloudsqlconnect.FindVM(ctx, svc, project, vmName)\n    if err == nil || !isTransient(err) { break }\n    time.Sleep(time.Duration(attempt+1) * time.Second)\n}","handlingStrategy":"retry","validationCode":"// preflight permission check\n_, err := svc.Projects.Get(project).Do()\nif err != nil {\n    return fmt.Errorf(\"project %s not accessible or Compute API disabled: %w\", project, err)\n}","typeGuard":null,"tryCatchPattern":"vm, zone, err := cloudsqlconnect.FindVM(ctx, svc, project, vmName)\nif err != nil {\n    var ge *googleapi.Error\n    if errors.As(err, &ge) && ge.Code == 403 {\n        return fmt.Errorf(\"grant compute.viewer on project %s\", project)\n    }\n    if isTransient(err) { /* exponential backoff retry */ }\n    return err\n}","preventionTips":["Grant roles/compute.viewer to the caller's service account","Enable the Compute Engine API on the project","Retry transient 5xx with backoff; distinguish from permanent 4xx","Confirm the project ID and VM name are correct before searching"],"tags":["gcp","compute-engine","api-error","permissions"],"backgroundTag":"compute-api-list-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"}