googleapis/mcp-toolbox · error

failed to create search entries iterator

Error message

failed to create search entries iterator

What it means

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().

Source

Thrown at internal/sources/dataplex/searchcatalog/search_catalog.go:104

}

// ExtractType extracts the mapped type from a resource string based on a type map.
func ExtractType(resourceString string, typeMap map[string]string) string {
	lastIndex := strings.LastIndex(resourceString, "/")
	if lastIndex == -1 {
		return resourceString
	}
	return typeMap[resourceString[lastIndex+1:]]
}

// ExecuteSearch performs the search and processes results.
func ExecuteSearch(ctx context.Context, client *dataplexapi.CatalogClient, req *dataplexpb.SearchEntriesRequest, typeMap map[string]string) ([]DataplexSearchResponse, error) {
	if client == nil {
		return nil, fmt.Errorf("dataplex catalog client is nil")
	}
	it := client.SearchEntries(ctx, req)
	if it == nil {
		return nil, fmt.Errorf("failed to create search entries iterator")
	}

	var results []DataplexSearchResponse
	for req.PageSize <= 0 || len(results) < int(req.PageSize) {
		entry, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return nil, err
		}
		entrySource := entry.DataplexEntry.GetEntrySource()

		resp := DataplexSearchResponse{
			DisplayName:   entrySource.GetDisplayName(),
			Description:   entrySource.GetDescription(),
			Type:          ExtractType(entry.DataplexEntry.GetEntryType(), typeMap),
			Resource:      entrySource.GetResource(),

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Log/inspect the constructed query from ConstructSearchQuery and ensure it is non-empty
  2. Ensure pageSize is a sane positive value and request fields are populated
  3. Re-create the CatalogClient with correct project/region and credentials
  4. Upgrade the dataplex Go SDK to the latest version

Example fix

// before
query := ConstructSearchQuery(prompt, nil, nil, nil, systemName) // may be empty
// after
if prompt == "" && len(projectIds) == 0 && len(parentIds) == 0 {
    return nil, errors.New("search requires a prompt or project/parent filter")
}
query := ConstructSearchQuery(prompt, projectIds, parentIds, types, systemName)
Defensive patterns

Strategy: validation

Validate before calling

if req.Query == "" { return errors.New("search query must not be empty") }
if req.PageSize < 0 { return errors.New("pageSize must be non-negative") }

Try / catch

res, err := searchcatalog.ExecuteSearch(ctx, client, req, typeMap)
if err != nil {
	if strings.Contains(err.Error(), "failed to create search entries iterator") {
		// inspect req/req.Query and retry with corrected request
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Prompt produced an empty query string after ConstructSearchQuery; projectIds/parentIds/types filtered everything out; SDK version mismatch where SearchEntries short-circuits on invalid input.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/fb81d002b147d013. Report an issue: GitHub.