GoogleContainerTools/skaffold · error

marshaling config: %w

Error message

marshaling config: %w

What it means

WriteFullConfig serializes the GlobalConfig to YAML before writing it to disk; it wraps yaml.Marshal failures with this error. Since GlobalConfig is a plain struct this is rare, and indicates config data that cannot be marshaled (e.g. corrupt in-memory state from a bad plugin or test fixture).

Source

Thrown at pkg/skaffold/config/util.go:533

	fullConfig, err := ReadConfigFile(configFile)
	if err != nil {
		return err
	}
	if fullConfig.Global == nil {
		fullConfig.Global = &ContextConfig{}
	}
	fullConfig.Global.CollectMetrics = &collectMetrics
	err = WriteFullConfig(configFile, fullConfig)
	if err != nil {
		return err
	}
	return err
}

func WriteFullConfig(configFile string, cfg *GlobalConfig) error {
	contents, err := yaml.Marshal(cfg)
	if err != nil {
		return fmt.Errorf("marshaling config: %w", err)
	}
	configFileOrDefault, err := ResolveConfigFile(configFile)
	if err != nil {
		return err
	}
	if err := os.WriteFile(configFileOrDefault, contents, 0644); err != nil {
		return fmt.Errorf("writing config file: %w", err)
	}
	return nil
}

func UpdateUserSurveyTaken(configFile string, id string) error {
	ai := fmt.Sprintf(updateUserTaken, id)
	aiErr := fmt.Errorf("could not automatically update the survey prompted timestamp - please run `%s`", ai)
	configFile, err := ResolveConfigFile(configFile)
	if err != nil {
		return aiErr
	}

View on GitHub (pinned to a1189de023)

Solutions

  1. Inspect the cfg you pass in for unsupported values (channels, funcs, cyclic references) and fix them
  2. Load the config via ReadConfigFile instead of constructing GlobalConfig by hand
  3. Upgrade/downgrade skaffold if a version-specific GlobalConfig type is at fault

Example fix

// before
cfg := &config.GlobalConfig{}
cfg.Kubecontexts = map[string]interface{}{"dev": make(chan int)}
WriteFullConfig("", cfg) // marshaling config: ...
// after
cfg, err := config.ReadConfigFile("")
// modify then write
config.WriteFullConfig("", cfg)
Defensive patterns

Strategy: try-catch

Validate before calling

func canMarshal(cfg *config.GlobalConfig) error {
  _, err := yaml.Marshal(cfg)
  return err
}
// call before WriteFullConfig

Try / catch

if err := config.WriteFullConfig(configFile, cfg); err != nil {
  if strings.Contains(err.Error(), "marshaling config") {
    return fmt.Errorf("cannot serialize global config: %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling WriteFullConfig (via writeConfig, UpdateMsgDisplayed, UpdateHaTSSurveyTaken, UpdateGlobalSurveyPrompted, UpdateGlobalCollectMetrics, UpdateUserSurveyTaken) with a *GlobalConfig containing fields yaml.Marshal cannot encode — practically only custom/unusual values injected programmatically.

Common situations: Programmatic modification of GlobalConfig with unsupported values (channels, funcs, cyclic pointers); fuzz/fixture data; Go type changes across skaffold versions breaking encode assumptions.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/4a54aa47134bf178. Report an issue: GitHub.