googleapis/mcp-toolbox · error

failed to parse project number %q as int64: %w

Error message

failed to parse project number %q as int64: %w

What it means

The source extracts the project number string from the second segment of the GetProject resource name and converts it with strconv.ParseInt. This error wraps a strconv failure when that segment is not a valid int64. Like the format error, it is a defensive guard against an unexpected Resource Manager response and is rare in practice.

Source

Thrown at internal/sources/dataplex/dataplex.go:116

		projectsClient.Close()
		return nil, fmt.Errorf("failed to get project details for project %q: %w", r.Project, err)
	}
	parts := strings.Split(proj.Name, "/")
	if len(parts) < 2 {
		client.Close()
		dataScanClient.Close()
		dataProductClient.Close()
		projectsClient.Close()
		return nil, fmt.Errorf("unexpected project resource name format: %q", proj.Name)
	}
	projectNumberStr := parts[1]
	projectNumber, err := strconv.ParseInt(projectNumberStr, 10, 64)
	if err != nil {
		client.Close()
		dataScanClient.Close()
		dataProductClient.Close()
		projectsClient.Close()
		return nil, fmt.Errorf("failed to parse project number %q as int64: %w", projectNumberStr, err)
	}

	s := &Source{
		Config:            r,
		Client:            client,
		DataScanClient:    dataScanClient,
		dataProductClient: dataProductClient,
		projectsClient:    projectsClient,
		projectNumber:     projectNumber,
	}

	return s, nil
}

var _ sources.Source = &Source{}

type Source struct {
	Config

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Confirm GetProject is hitting the real Google API (remove mocks/proxies that may return `projects/<project-id>` instead of `projects/<number>`).
  2. Retry initialization to rule out a transient malformed response.
  3. Update cloud.google.com/go/resourcemanager to the latest version and file an issue with Google if the real API returns a non-numeric second segment.
Defensive patterns

Strategy: try-catch

Try / catch

src, err := cfg.Initialize(ctx, tracer)
if err != nil {
	if strings.Contains(err.Error(), "failed to parse project number") {
		log.Printf("unexpected project number from API; retrying: %v", err)
		return cfg.Initialize(ctx, tracer)
	}
	return err
}

Prevention

When it happens

Trigger: Initialize runs strconv.ParseInt(projectNumberStr, 10, 64) on parts[1] of proj.Name and the string is not a decimal integer (e.g. an alphanumeric project ID was returned instead of a numeric project number).

Common situations: Custom/mock Resource Manager endpoints returning the project ID rather than the number in the resource name; altered or proxied API responses; corrupted service responses.

Understand the failure class

Related errors


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