googleapis/mcp-toolbox · error

dataplex catalog client is nil

Error message

dataplex catalog client is nil

What it means

ExecuteSearch is the package-level search runner for the Dataplex searchcatalog tool and requires a *dataplexapi.CatalogClient. A nil client means the searchcatalog source was never initialized with a working CatalogClient, so no search can be issued. The guard prevents a nil-pointer panic deep inside SearchEntries.

Source

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

		queryParts = append(queryParts, "system="+system)
	}

	return fmt.Sprintf("%s %s", prompt, strings.Join(queryParts, " AND "))
}

// 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{

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the Dataplex Catalog API (dataplex.googleapis.com) is enabled
  2. Re-initialize the Dataplex source with valid credentials so the CatalogClient is created
  3. Check the source config/Region so the client is built for the intended project
  4. Add an init-time check that logs/warns when CatalogClient is nil instead of failing at search time

Example fix

// before
res, err := searchcatalog.ExecuteSearch(ctx, nil, req, typeMap)
// after
if client == nil {
    return nil, errors.New("catalog client missing: re-initialize dataplex source")
}
res, err := searchcatalog.ExecuteSearch(ctx, client, req, typeMap)
Defensive patterns

Strategy: type-guard

Validate before calling

if client == nil { return errors.New("catalog client missing: re-initialize dataplex source") }

Type guard

func hasCatalogClient(s *sources.Dataplex) bool { return s != nil && s.CatalogClient != nil }

Try / catch

res, err := searchcatalog.ExecuteSearch(ctx, client, req, typeMap)
if err != nil {
	if strings.Contains(err.Error(), "catalog client is nil") {
		// re-create the dataplex source / enable API
	}
	return err
}

Prevention

When it happens

Trigger: Invoking the search_catalog tool when the enclosing Dataplex source failed to construct its CatalogClient (disabled API, missing credentials, source config skipped catalog client creation) and passed nil into ExecuteSearch.

Common situations: Dataplex API not enabled on the project; credential/ADC setup failure during source initialization; running the tool against a source variant that only initializes the DataScan client.

Related errors


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