{"record":{"id":"fb81d002b147d013","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-search-entries-iterator","errorCode":null,"errorMessage":"failed to create search entries iterator","messagePattern":"failed to create search entries iterator","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/dataplex/searchcatalog/search_catalog.go","lineNumber":104,"sourceCode":"}\n\n// ExtractType extracts the mapped type from a resource string based on a type map.\nfunc ExtractType(resourceString string, typeMap map[string]string) string {\n\tlastIndex := strings.LastIndex(resourceString, \"/\")\n\tif lastIndex == -1 {\n\t\treturn resourceString\n\t}\n\treturn typeMap[resourceString[lastIndex+1:]]\n}\n\n// ExecuteSearch performs the search and processes results.\nfunc ExecuteSearch(ctx context.Context, client *dataplexapi.CatalogClient, req *dataplexpb.SearchEntriesRequest, typeMap map[string]string) ([]DataplexSearchResponse, error) {\n\tif client == nil {\n\t\treturn nil, fmt.Errorf(\"dataplex catalog client is nil\")\n\t}\n\tit := client.SearchEntries(ctx, req)\n\tif it == nil {\n\t\treturn nil, fmt.Errorf(\"failed to create search entries iterator\")\n\t}\n\n\tvar results []DataplexSearchResponse\n\tfor req.PageSize <= 0 || len(results) < int(req.PageSize) {\n\t\tentry, err := it.Next()\n\t\tif err == iterator.Done {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tentrySource := entry.DataplexEntry.GetEntrySource()\n\n\t\tresp := DataplexSearchResponse{\n\t\t\tDisplayName:   entrySource.GetDisplayName(),\n\t\t\tDescription:   entrySource.GetDescription(),\n\t\t\tType:          ExtractType(entry.DataplexEntry.GetEntryType(), typeMap),\n\t\t\tResource:      entrySource.GetResource(),","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/dataplex/searchcatalog/search_catalog.go#L86-L122","documentation":"After the nil-client guard, ExecuteSearch calls client.SearchEntries(ctx, req) to get a result iterator. A nil iterator means the SDK could not begin the search (client in a bad state, invalid request such as empty query/pageSize conflicts). The function converts that condition into this explicit error instead of panicking on it.Next().","triggerScenarios":"Calling the search_catalog tool with a CatalogClient whose SearchEntries returns nil — typically due to an invalid SearchEntriesRequest (empty query, malformed scope) or a degraded client.","commonSituations":"Prompt produced an empty query string after ConstructSearchQuery; projectIds/parentIds/types filtered everything out; SDK version mismatch where SearchEntries short-circuits on invalid input.","solutions":["Log/inspect the constructed query from ConstructSearchQuery and ensure it is non-empty","Ensure pageSize is a sane positive value and request fields are populated","Re-create the CatalogClient with correct project/region and credentials","Upgrade the dataplex Go SDK to the latest version"],"exampleFix":"// before\nquery := ConstructSearchQuery(prompt, nil, nil, nil, systemName) // may be empty\n// after\nif prompt == \"\" && len(projectIds) == 0 && len(parentIds) == 0 {\n    return nil, errors.New(\"search requires a prompt or project/parent filter\")\n}\nquery := ConstructSearchQuery(prompt, projectIds, parentIds, types, systemName)","handlingStrategy":"validation","validationCode":"if req.Query == \"\" { return errors.New(\"search query must not be empty\") }\nif req.PageSize < 0 { return errors.New(\"pageSize must be non-negative\") }","typeGuard":null,"tryCatchPattern":"res, err := searchcatalog.ExecuteSearch(ctx, client, req, typeMap)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failed to create search entries iterator\") {\n\t\t// inspect req/req.Query and retry with corrected request\n\t}\n\treturn err\n}","preventionTips":["Ensure ConstructSearchQuery produces a non-empty query","Sanity-check SearchEntriesRequest fields before executing","Keep the dataplex SDK up to date"],"tags":["dataplex","searchcatalog","iterator","gcp"],"backgroundTag":"nil-client-reference","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"}