{"record":{"id":"9a7a5ef47fd227ae","repo":"googleapis/mcp-toolbox","slug":"failed-to-delete-instance-w","errorCode":null,"errorMessage":"failed to delete instance: %w","messagePattern":"failed to delete instance: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigtable/admin_wrappers.go","lineNumber":64,"sourceCode":"\treturn map[string]string{\"status\": \"instance created successfully\"}, nil\n}\n\nfunc (s *Source) UpdateInstance(ctx context.Context, instanceId, displayName string) (any, error) {\n\tconf := &bigtable.InstanceWithClustersConfig{\n\t\tInstanceID:  instanceId,\n\t\tDisplayName: displayName,\n\t}\n\terr := s.InstanceAdmin.UpdateInstanceWithClusters(ctx, conf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to update instance: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"instance updated successfully\"}, nil\n}\n\nfunc (s *Source) DeleteInstance(ctx context.Context, instanceId string) (any, error) {\n\terr := s.InstanceAdmin.DeleteInstance(ctx, instanceId)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to delete instance: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"instance deleted successfully\"}, nil\n}\n\nfunc (s *Source) ListInstances(ctx context.Context) (any, error) {\n\tinstances, err := s.InstanceAdmin.Instances(ctx)\n\tif err != nil {\n\t\tvar partialErr bigtable.ErrPartiallyUnavailable\n\t\tif errors.As(err, &partialErr) {\n\t\t\treturn instances, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to list instances: %w\", err)\n\t}\n\treturn instances, nil\n}\n\nfunc (s *Source) GetCluster(ctx context.Context, instanceId, clusterId string) (any, error) {\n\tcluster, err := s.InstanceAdmin.GetCluster(ctx, instanceId, clusterId)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigtable/admin_wrappers.go#L46-L82","documentation":"This error is a wrapper raised by the Bigtable source's DeleteInstance method when the underlying InstanceAdmin.DeleteInstance call to the Cloud Bigtable Admin API fails. The original gRPC/googleapi error is preserved via %w, so callers can unwrap it with errors.As/Is to inspect codes like NotFound or PermissionDenied. It simply means the admin API rejected or failed the delete request for the given instance.","triggerScenarios":"Calling DeleteInstance(ctx, instanceId) when the instance does not exist (NotFound), the credentials/service account lack bigtable.instances.delete IAM permission (PermissionDenied), the instance is already being deleted, or transient gRPC/network failures interrupt the admin RPC.","commonSituations":"Typos or stale instance IDs after an instance was removed out-of-band; running with Application Default Credentials from an account missing the Bigtable Admin role; attempting deletion in the wrong project (misconfigured project env var); duplicate delete attempts in automation scripts.","solutions":["Verify the instance ID exists first with ListInstances or `gcloud bigtable instances list`.","Check IAM: grant the caller the roles/bigtable.admin (or bigtable.instances.delete) role on the project.","Confirm the correct project is configured (BIGTABLE_PROJECT_ID / client project option).","Unwrap the error with errors.As(*googleapi.Error) or status.FromError and branch on its code; retry only on transient codes (Unavailable, DeadlineExceeded)."],"exampleFix":"// before\nif err != nil {\n    return nil, fmt.Errorf(\"failed to delete instance: %w\", err)\n}\n// after\nif err != nil {\n    if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {\n        return map[string]string{\"status\": \"instance already deleted\"}, nil\n    }\n    return nil, fmt.Errorf(\"failed to delete instance: %w\", err)\n}","handlingStrategy":"type-guard","validationCode":"// before calling DeleteInstance\ninstances, _ := src.ListInstances(ctx)\nfor _, in := range instances.([]*bigtable.Instance) {\n    if in.Name == instanceId {\n        exists = true\n    }\n}\nif !exists {\n    return // skip delete; instance already gone\n}","typeGuard":"func isNotFound(err error) bool {\n    var ge *googleapi.Error\n    if errors.As(err, &ge) {\n        return ge.Code == 404\n    }\n    if st, ok := status.FromError(errors.Unwrap(err)); ok {\n        return st.Code() == codes.NotFound\n    }\n    return false\n}","tryCatchPattern":"if _, err := src.DeleteInstance(ctx, id); err != nil {\n    var wrapped *fmt.WrapError // or just unwrap generically\n    if isNotFound(err) {\n        log.Printf(\"instance %s already deleted\", id)\n        return\n    }\n    return fmt.Errorf(\"delete instance %s: %w\", id, err)\n}","preventionTips":["Always check existence with ListInstances before deleting in idempotent automation.","Grant the service account roles/bigtable.admin explicitly and audit with IAM Policy Analyzer.","Pin and verify the project ID in configuration before constructing the admin client.","Unwrap and branch on gRPC status codes instead of retrying every failure."],"tags":["gcp","bigtable","admin-api","error-wrapping"],"backgroundTag":"bigtable-admin-api-error","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"}