{"record":{"id":"4a54aa47134bf178","repo":"GoogleContainerTools/skaffold","slug":"marshaling-config-w-4a54aa","errorCode":null,"errorMessage":"marshaling config: %w","messagePattern":"marshaling config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/config/util.go","lineNumber":533,"sourceCode":"\tfullConfig, err := ReadConfigFile(configFile)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif fullConfig.Global == nil {\n\t\tfullConfig.Global = &ContextConfig{}\n\t}\n\tfullConfig.Global.CollectMetrics = &collectMetrics\n\terr = WriteFullConfig(configFile, fullConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn err\n}\n\nfunc WriteFullConfig(configFile string, cfg *GlobalConfig) error {\n\tcontents, err := yaml.Marshal(cfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshaling config: %w\", err)\n\t}\n\tconfigFileOrDefault, err := ResolveConfigFile(configFile)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := os.WriteFile(configFileOrDefault, contents, 0644); err != nil {\n\t\treturn fmt.Errorf(\"writing config file: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc UpdateUserSurveyTaken(configFile string, id string) error {\n\tai := fmt.Sprintf(updateUserTaken, id)\n\taiErr := fmt.Errorf(\"could not automatically update the survey prompted timestamp - please run `%s`\", ai)\n\tconfigFile, err := ResolveConfigFile(configFile)\n\tif err != nil {\n\t\treturn aiErr\n\t}","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/config/util.go#L515-L551","documentation":"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).","triggerScenarios":"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.","commonSituations":"Programmatic modification of GlobalConfig with unsupported values (channels, funcs, cyclic pointers); fuzz/fixture data; Go type changes across skaffold versions breaking encode assumptions.","solutions":["Inspect the cfg you pass in for unsupported values (channels, funcs, cyclic references) and fix them","Load the config via ReadConfigFile instead of constructing GlobalConfig by hand","Upgrade/downgrade skaffold if a version-specific GlobalConfig type is at fault"],"exampleFix":"// before\ncfg := &config.GlobalConfig{}\ncfg.Kubecontexts = map[string]interface{}{\"dev\": make(chan int)}\nWriteFullConfig(\"\", cfg) // marshaling config: ...\n// after\ncfg, err := config.ReadConfigFile(\"\")\n// modify then write\nconfig.WriteFullConfig(\"\", cfg)","handlingStrategy":"try-catch","validationCode":"func canMarshal(cfg *config.GlobalConfig) error {\n  _, err := yaml.Marshal(cfg)\n  return err\n}\n// call before WriteFullConfig","typeGuard":null,"tryCatchPattern":"if err := config.WriteFullConfig(configFile, cfg); err != nil {\n  if strings.Contains(err.Error(), \"marshaling config\") {\n    return fmt.Errorf(\"cannot serialize global config: %w\", err)\n  }\n  return err\n}","preventionTips":["Don't inject non-serializable values (channels, funcs, cycles) into GlobalConfig","Round-trip test yaml.Marshal/Unmarshal on GlobalConfig in CI","Build configs from ReadConfigFile output rather than ad-hoc structs"],"tags":["yaml","serialization","config-write"],"backgroundTag":"yaml-marshal-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}