{"record":{"id":"1f8ccf8236328eb9","repo":"GoogleContainerTools/skaffold","slug":"merging-context-specific-and-global-config-w","errorCode":null,"errorMessage":"merging context-specific and global config: %w","messagePattern":"merging context-specific and global config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/config/util.go","lineNumber":164,"sourceCode":"\t\t}\n\t\treturn cfg.Global, nil\n\t}\n\n\tvar mergedConfig ContextConfig\n\tfor _, contextCfg := range cfg.ContextConfigs {\n\t\tif util.RegexEqual(contextCfg.Kubecontext, kubeContext) {\n\t\t\tlog.Entry(context.TODO()).Debugf(\"found config for context %q\", kubeContext)\n\t\t\tmergedConfig = *contextCfg\n\t\t}\n\t}\n\t// in case there was no config for this kubeContext in cfg.ContextConfigs\n\tmergedConfig.Kubecontext = kubeContext\n\n\tif cfg.Global != nil {\n\t\t// if values are unset for the current context, retrieve\n\t\t// the global config and use its values as a fallback.\n\t\tif err := mergo.Merge(&mergedConfig, cfg.Global, mergo.WithAppendSlice); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"merging context-specific and global config: %w\", err)\n\t\t}\n\t}\n\treturn &mergedConfig, nil\n}\n\nfunc GetDefaultRepo(configFile string, cliValue *string) (string, error) {\n\t// CLI flag takes precedence.\n\tif cliValue != nil {\n\t\treturn *cliValue, nil\n\t}\n\tcfg, err := GetConfigForCurrentKubectx(configFile)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif cfg.DefaultRepo != \"\" {\n\t\tlog.Entry(context.TODO()).Infof(\"Using default-repo=%s from config\", cfg.DefaultRepo)\n\t}\n\treturn cfg.DefaultRepo, nil","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/config/util.go#L146-L182","documentation":"getConfigForKubeContextWithGlobalDefaults starts from the context-specific config and, when cfg.Global is set, merges global defaults into it via mergo (WithAppendSlice). This error means the mergo merge itself failed — rare, but it makes the resulting per-context config unreliable so the library aborts.","triggerScenarios":"Calling getConfigForKubeContextWithGlobalDefaults (via GetConfigForCurrentKubectx) where the context-specific GlobalConfig contains fields mergo cannot merge with the global config (e.g. incompatible slice/map types after schema drift or a hand-edited file).","commonSituations":"Config files written by a different skaffold version with a changed GlobalConfig schema; manually edited config.yaml with wrong field types for a kubecontext entry.","solutions":["Inspect the per-kubecontext entries in ~/.skaffold/config.yaml for fields with unexpected types and fix them","Remove the suspect kubecontext section and let skaffold regenerate defaults","Align file format with your skaffold version (upgrade or downgrade so schemas match)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"func validateGlobalConfigShape(path string) error {\n  cfg, err := config.ReadConfigFileNoCache(path)\n  if err != nil { return err }\n  for kctx, kc := range cfg.Kubecontexts {\n    if kc == nil { return fmt.Errorf(\"kubecontext %q is null\", kctx) }\n  }\n  return nil\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.GetConfigForCurrentKubectx(configFile)\nif err != nil && strings.Contains(err.Error(), \"merging context-specific and global config\") {\n  log.Warn(\"falling back to context config without global defaults\")\n  cfg, err = readContextConfigOnly(configFile)\n}","preventionTips":["Don't hand-edit typed fields in the kubecontexts section","Keep skaffold version consistent with the config file schema","Regenerate per-context entries instead of patching them manually"],"tags":["config","merge","kubecontext"],"backgroundTag":"config-merge-conflict","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"}