googleapis/mcp-toolbox · error

failed to unmarshal runtimeConfig: %w

Error message

failed to unmarshal runtimeConfig: %w

What it means

When the createbatch tool config includes a runtimeConfig section, it is decoded into dataprocpb.RuntimeConfig via protojson. This error is thrown when the JSON produced from the YAML does not match the RuntimeConfig proto schema — unknown fields, wrong types, or invalid enum values — and the actual protojson error is wrapped after the colon.

Source

Thrown at internal/tools/serverlessspark/createbatch/config.go:83

	if err := decoder.DecodeContext(ctx, &ymlCfg); err != nil {
		return Config{}, err
	}

	cfg := Config{
		ConfigBase: tools.ConfigBase{
			Name:         name,
			Description:  ymlCfg.Description,
			AuthRequired: ymlCfg.AuthRequired,
		},
		Type:   ymlCfg.Type,
		Source: ymlCfg.Source,
	}

	if ymlCfg.RuntimeConfig != nil {
		rc := &dataprocpb.RuntimeConfig{}
		if err := unmarshalProto(ymlCfg.RuntimeConfig, rc); err != nil {
			return Config{}, fmt.Errorf("failed to unmarshal runtimeConfig: %w", err)
		}
		cfg.RuntimeConfig = rc
	}

	if ymlCfg.EnvironmentConfig != nil {
		ec := &dataprocpb.EnvironmentConfig{}
		if err := unmarshalProto(ymlCfg.EnvironmentConfig, ec); err != nil {
			return Config{}, fmt.Errorf("failed to unmarshal environmentConfig: %w", err)
		}
		cfg.EnvironmentConfig = ec
	}

	return cfg, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Read the wrapped protojson error after 'failed to unmarshal runtimeConfig:' to find the offending field
  2. Cross-check the runtimeConfig keys against the dataprocpb.RuntimeConfig schema (ContainerImage, Properties, ServiceAccount, NetworkConfig, etc.)
  3. Fix field names to exact proto JSON names (lowerCamelCase) and correct value types
  4. Remove unknown/unsupported fields from the runtimeConfig block

Example fix

# before
runtimeConfig:
  serviceaccount: my-sa@proj.iam.gserviceaccount.com
  containerimage: us.gcr.io/img
# after
runtimeConfig:
  serviceAccount: my-sa@proj.iam.gserviceaccount.com
  containerImage: us.gcr.io/img
Defensive patterns

Strategy: validation

Validate before calling

// Validate runtimeConfig keys against the known proto JSON names before load
var rc dataprocpb.RuntimeConfig
b, _ := json.Marshal(rawRuntimeConfig)
if err := protojson.Unmarshal(b, &rc); err != nil {
    return fmt.Errorf("bad runtimeConfig: %w", err)
}
_ = NewConfig(ctx, yml)

Type guard

func validRuntimeConfig(v any) bool {
    var rc dataprocpb.RuntimeConfig
    b, err := json.Marshal(v)
    return err == nil && protojson.Unmarshal(b, &rc) == nil
}

Try / catch

cfg, err := createbatch.NewConfig(ctx, ymlCfg)
if err != nil {
    if strings.Contains(err.Error(), "failed to unmarshal runtimeConfig") {
        log.Fatalf("fix runtimeConfig fields per dataprocpb.RuntimeConfig schema: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: A Serverless Spark createbatch tool YAML contains a runtimeConfig block with a field that is not part of dataprocpb.RuntimeConfig (typo, wrong casing) or a value of the wrong type (string where enum/int expected), passed to NewConfig during startup.

Common situations: Typos like 'containerImage' instead of 'containerImage' casing issues, using 'region' inside runtimeConfig instead of environmentConfig, wrong types for serviceAccount fields, or fields from an older/newer Dataproc proto version.

Related errors


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