{"record":{"id":"484acd7e7f955b99","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-logical-view-w","errorCode":null,"errorMessage":"failed to create logical view: %w","messagePattern":"failed to create logical view: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigtable/admin_wrappers.go","lineNumber":212,"sourceCode":"\treturn views, nil\n}\n\nfunc (s *Source) ListMaterializedViews(ctx context.Context, instanceId string) (any, error) {\n\tviews, err := s.InstanceAdmin.MaterializedViews(ctx, instanceId)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list materialized views: %w\", err)\n\t}\n\treturn views, nil\n}\n\nfunc (s *Source) CreateLogicalView(ctx context.Context, instanceId, logicalViewId, query string) (any, error) {\n\tconf := &bigtable.LogicalViewInfo{\n\t\tLogicalViewID: logicalViewId,\n\t\tQuery:         query,\n\t}\n\terr := s.InstanceAdmin.CreateLogicalView(ctx, instanceId, conf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create logical view: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"logical view created successfully\"}, nil\n}\n\nfunc (s *Source) UpdateLogicalView(ctx context.Context, instanceId, logicalViewId, query string) (any, error) {\n\tconf := bigtable.LogicalViewInfo{ // MUST be value per bigtable SDK\n\t\tLogicalViewID: logicalViewId,\n\t\tQuery:         query,\n\t}\n\terr := s.InstanceAdmin.UpdateLogicalView(ctx, instanceId, conf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to update logical view: %w\", err)\n\t}\n\treturn map[string]string{\"status\": \"logical view updated successfully\"}, nil\n}\n\nfunc (s *Source) DeleteLogicalView(ctx context.Context, instanceId, logicalViewId string) (any, error) {\n\terr := s.InstanceAdmin.DeleteLogicalView(ctx, instanceId, logicalViewId)","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigtable/admin_wrappers.go#L194-L230","documentation":"CreateLogicalView wraps errors from InstanceAdmin.CreateLogicalView. A logical view is a named SQL query over a Bigtable instance; creation fails if the ID already exists, the query is invalid/unsupported, permissions are missing, or the instance ID is wrong. The underlying SDK error is wrapped with %w.","triggerScenarios":"Calling CreateLogicalView (bigtable_create_logical_view tool) when: logicalViewId already exists (AlreadyExists), the SQL query fails validation, caller lacks bigtable.views.create permission, or the instanceId does not exist.","commonSituations":"Re-running an idempotent-create script against an existing view; SQL query referencing non-existent tables/column families; service account without Bigtable Admin role; typo'd instance name.","solutions":["Check errors.Is(err, 4xx googleapi.Status) for AlreadyExists and choose a new logicalViewId or delete/update the existing view","Validate the SQL query against the instance's actual tables and column families before creating","Grant roles/bigtable.admin (or bigtable.views.create) to the caller's service account","Confirm instanceId and project are correct with gcloud bigtable instances list"],"exampleFix":"// before: blind retry fails with 'already exists'\nerr := s.InstanceAdmin.CreateLogicalView(ctx, instanceId, conf)\n// after: pre-check then create\nexisting, _ := s.InstanceAdmin.ListLogicalViews(ctx, instanceId)\nif containsID(existing, logicalViewId) {\n    return s.InstanceAdmin.UpdateLogicalView(ctx, instanceId, bigtable.LogicalViewInfo{LogicalViewID: logicalViewId, Query: query})\n}\nerr := s.InstanceAdmin.CreateLogicalView(ctx, instanceId, conf)","handlingStrategy":"validation","validationCode":"func validateLogicalViewInput(instanceId, viewId, query string) error {\n    if instanceId == \"\" || viewId == \"\" || query == \"\" {\n        return errors.New(\"instanceId, logicalViewId and query are required\")\n    }\n    if !regexp.MustCompile(`^[a-zA-Z0-9._-]{1,255}$`).MatchString(viewId) {\n        return fmt.Errorf(\"invalid logical view id %q\", viewId)\n    }\n    return nil\n}","typeGuard":"func isAlreadyExists(err error) bool {\n    st, ok := status.FromError(errors.Unwrap(err))\n    return ok && st.Code() == codes.AlreadyExists\n}","tryCatchPattern":"res, err := src.CreateLogicalView(ctx, instanceId, viewId, query)\nif err != nil {\n    if isAlreadyExists(err) {\n        return src.UpdateLogicalView(ctx, instanceId, viewId, query) // create-or-update\n    }\n    return err\n}","preventionTips":["Check whether the logical view already exists (list/get) before creating to make scripts idempotent","Validate the SQL query against the instance's tables and column families first","Ensure the service account has the Bigtable Admin role","Use valid resource IDs (1-255 chars, letters/digits/dash/dot/underscore)"],"tags":["gcp","bigtable","admin-api","permissions"],"backgroundTag":"gcp-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"}