{"record":{"id":"ea693d7e95a144f3","repo":"googleapis/mcp-toolbox","slug":"error-listing-databases-w","errorCode":null,"errorMessage":"error listing databases: %w","messagePattern":"error listing databases: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqladmin/cloud_sql_admin.go","lineNumber":249,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tresp, err := service.Instances.Get(projectId, instanceId).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting instance: %w\", err)\n\t}\n\treturn resp, nil\n}\n\nfunc (s *Source) ListDatabase(ctx context.Context, project, 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\tresp, err := service.Databases.List(project, instance).Do()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing databases: %w\", err)\n\t}\n\n\tif resp.Items == nil {\n\t\treturn []any{}, nil\n\t}\n\n\ttype databaseInfo struct {\n\t\tName      string `json:\"name\"`\n\t\tCharset   string `json:\"charset\"`\n\t\tCollation string `json:\"collation\"`\n\t}\n\n\tvar databases []databaseInfo\n\tfor _, item := range resp.Items {\n\t\tdatabases = append(databases, databaseInfo{\n\t\t\tName:      item.Name,\n\t\t\tCharset:   item.Charset,\n\t\t\tCollation: item.Collation,","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqladmin/cloud_sql_admin.go#L231-L267","documentation":"Thrown in ListDatabase when the sqladmin Databases.List call (projects.instances.databases.list) fails. Listing databases for an instance returned an API error before the code could normalize resp.Items to an empty slice.","triggerScenarios":"Calling the list_databases tool against a non-existent instance, wrong project, or with a principal lacking cloudsql.databases.list permission.","commonSituations":"Instance deleted between tool selection and invocation; project ID mismatch; service account missing roles/cloudsql.viewer; transient 500/503 from the Cloud SQL API.","solutions":["Confirm the instance exists and is runnable (get_instance).","Fix the project ID and re-run.","Grant roles/cloudsql.viewer to the calling principal.","Retry on transient 5xx errors with backoff.","Inspect the wrapped googleapi.Error code for the exact failure reason."],"exampleFix":"null","handlingStrategy":"retry","validationCode":"if instance == \"\" {\n    return fmt.Errorf(\"instance is required to list databases\")\n}\n// verify instance exists first\nif _, err := src.GetInstance(ctx, project, instance, token); err != nil {\n    return fmt.Errorf(\"cannot list databases; instance unavailable: %w\", err)\n}","typeGuard":"func isRetryable(err error) bool {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) {\n        return gerr.Code == 429 || gerr.Code >= 500\n    }\n    return false\n}","tryCatchPattern":"var out any\nvar err error\nfor attempt := 0; attempt < 3; attempt++ {\n    out, err = src.ListDatabase(ctx, project, instance, token)\n    if err == nil || !isRetryable(err) {\n        break\n    }\n    time.Sleep(time.Duration(1<<attempt) * time.Second)\n}\nif err != nil {\n    return fmt.Errorf(\"list databases failed after retries: %w\", err)\n}","preventionTips":["Retry transient 429/5xx with exponential backoff.","Verify the instance exists and is RUNNABLE before listing.","Grant roles/cloudsql.viewer to the calling principal.","Handle empty result gracefully — the library already returns []any{} when there are no databases."],"tags":["gcp","cloud-sql","api-error","listing"],"backgroundTag":"cloudsql-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"}