googleapis/mcp-toolbox · error

failed to parse batch name: %s

Error message

failed to parse batch name: %s

What it means

The batchFullNameRegex failed to match the given batch name: it does not follow projects/<project>/locations/<location>/batches/<batch_id>, so project, location and batch ID cannot be extracted.

Source

Thrown at internal/sources/serverlessspark/url.go:38

	"regexp"
	"time"

	"cloud.google.com/go/dataproc/v2/apiv1/dataprocpb"
)

var batchFullNameRegex = regexp.MustCompile(`projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/batches/(?P<batch_id>[^/]+)`)
var sessionTemplateFullNameRegex = regexp.MustCompile(`projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/sessionTemplates/(?P<template_id>[^/]+)`)

const (
	logTimeBufferBefore = 1 * time.Minute
	logTimeBufferAfter  = 10 * time.Minute
)

// Extract BatchDetails extracts the project ID, location, and batch ID from a fully qualified batch name.
func ExtractBatchDetails(batchName string) (projectID, location, batchID string, err error) {
	matches := batchFullNameRegex.FindStringSubmatch(batchName)
	if len(matches) < 4 {
		return "", "", "", fmt.Errorf("failed to parse batch name: %s", batchName)
	}
	return matches[1], matches[2], matches[3], nil
}

// BatchConsoleURL builds a URL to the Google Cloud Console linking to the batch summary page.
func BatchConsoleURL(projectID, location, batchID string) string {
	return fmt.Sprintf("https://console.cloud.google.com/dataproc/batches/%s/%s/summary?project=%s", location, batchID, projectID)
}

// BatchLogsURL builds a URL to the Google Cloud Console showing Cloud Logging for the given batch and time range.
//
// The implementation adds some buffer before and after the provided times.
func BatchLogsURL(projectID, location, batchID string, startTime, endTime time.Time) string {
	advancedFilterTemplate := `resource.type="cloud_dataproc_batch"
resource.labels.project_id="%s"
resource.labels.location="%s"
resource.labels.batch_id="%s"`
	advancedFilter := fmt.Sprintf(advancedFilterTemplate, projectID, location, batchID)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Pass a fully qualified batch name of the form projects/P/locations/L/batches/B
  2. Check for typos, URL encoding or extra path segments in the name
  3. Verify the value came from the Dataproc API unmodified
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/sources/serverlessspark/url.go:38 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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