googleapis/mcp-toolbox · error
failed to cancel operation: %w
Error message
failed to cancel operation: %w
What it means
The longrunning CancelOperation RPC for the Dataproc operation failed — the operation name may be invalid/already finished, or the API call was rejected due to permissions or connectivity.
Source
Thrown at internal/sources/serverlessspark/serverlessspark.go:166
func (s *Source) GetOperationsClient(ctx context.Context) (*longrunning.OperationsClient, error) {
return s.OpsClient, nil
}
func (s *Source) Close() error {
return errors.Join(s.BatchClient.Close(), s.SessionClient.Close(), s.SessionTemplateClient.Close(), s.OpsClient.Close())
}
func (s *Source) CancelOperation(ctx context.Context, operation string) (any, error) {
req := &longrunningpb.CancelOperationRequest{
Name: fmt.Sprintf("projects/%s/locations/%s/operations/%s", s.GetProject(), s.GetLocation(), operation),
}
client, err := s.GetOperationsClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get operations client: %w", err)
}
err = client.CancelOperation(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to cancel operation: %w", err)
}
return fmt.Sprintf("Cancelled [%s].", operation), nil
}
func (s *Source) CreateBatch(ctx context.Context, batch *dataprocpb.Batch) (map[string]any, error) {
req := &dataprocpb.CreateBatchRequest{
Parent: fmt.Sprintf("projects/%s/locations/%s", s.GetProject(), s.GetLocation()),
Batch: batch,
}
client := s.GetBatchControllerClient()
op, err := client.CreateBatch(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to create batch: %w", err)
}
meta, err := op.Metadata()
if err != nil {
return nil, fmt.Errorf("failed to get create batch op metadata: %w", err)View on GitHub (pinned to 8cc6e09de2)
Solutions
- Verify the operation ID exists and is still running for the project/location
- Check IAM permissions (dataproc operations cancel) and ADC validity
- Retry on transient API errors
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/sources/serverlessspark/serverlessspark.go:166 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/bad1ee8b5489700b.
Report an issue: GitHub.