{"record":{"id":"baf8424ffc82425f","repo":"GoogleContainerTools/skaffold","slug":"collecting-namespaces-w","errorCode":null,"errorMessage":"collecting namespaces: %w","messagePattern":"collecting namespaces: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/manifest/namespaces.go","lineNumber":45,"sourceCode":"\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/warnings\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/yaml\"\n)\n\nconst namespaceField = \"namespace\"\n\nconst defaultNamespace = \"default\"\n\n// CollectNamespaces returns all the namespaces in the manifests.\nfunc (l *ManifestList) CollectNamespaces() ([]string, error) {\n\treplacer := newNamespaceCollector()\n\n\t// TODO(aaron-prindle) make sure this is ok?\n\trs := &ResourceSelectorImages{}\n\tif _, err := l.Visit(replacer, rs); err != nil {\n\t\t// if _, err := l.Visit(replacer, make(map[schema.GroupKind]latest.ResourceFilter), make(map[schema.GroupKind]latest.ResourceFilter)); err != nil {\n\t\t// TODO(aaron-prindle) verify this doesn't need to support allow/deny list, also see if 'nil' is better option for unused inputs\n\t\treturn nil, fmt.Errorf(\"collecting namespaces: %w\", err)\n\t}\n\n\tnamespaces := make([]string, 0, len(replacer.namespaces))\n\tfor ns := range replacer.namespaces {\n\t\tnamespaces = append(namespaces, ns)\n\t}\n\tsort.Strings(namespaces)\n\treturn namespaces, nil\n}\n\ntype namespaceCollector struct {\n\tnamespaces map[string]bool\n}\n\nfunc newNamespaceCollector() *namespaceCollector {\n\treturn &namespaceCollector{\n\t\tnamespaces: map[string]bool{},\n\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/manifest/namespaces.go#L27-L63","documentation":"CollectNamespaces runs ManifestList.Visit with a ResourceSelectorImages visitor to gather the namespaces declared across all manifests. Any error surfacing from Visit (YAML/JSON decode failure, unmarshaling error, affinity error, etc.) is wrapped as 'collecting namespaces'.","triggerScenarios":"Calling ManifestList.CollectNamespaces (directly or via getObjectNamespaceIfDefined) when the underlying Visit fails — typically because a manifest in the list is invalid YAML or not a decodable Kubernetes object.","commonSituations":"Broken manifests produced by an upstream render step propagating as a namespace-collection failure; manifests referencing malformed CRDs or empty documents.","solutions":["Inspect the wrapped cause (%w) — it names the underlying manifest error; fix that document first","Validate all manifests with 'kubectl apply --dry-run=client' or yamllint before rendering/deploying","Fix the invalid YAML/JSON in the offending manifest (tabs, bad indentation, non-mapping documents)","Regenerate the manifest list from source if it was corrupted by a pipeline step"],"exampleFix":"// before: tabs break YAML parsing inside Visit\nspec:\n\treplicas: 1\n// after\nspec:\n  replicas: 1","handlingStrategy":"try-catch","validationCode":"import \"gopkg.in/yaml.v3\"\nfunc validateAll(manifests [][]byte) error {\n  for _, m := range manifests {\n    var v interface{}\n    if err := yaml.Unmarshal(m, &v); err != nil { return fmt.Errorf(\"invalid manifest %q: %w\", m, err) }\n  }\n  return nil\n}\n// run before CollectNamespaces","typeGuard":null,"tryCatchPattern":"ns, err := manifests.CollectNamespaces()\nif err != nil {\n  if strings.Contains(err.Error(), \"collecting namespaces\") {\n    // the wrapped cause identifies the bad manifest; log it and abort or skip\n    return fmt.Errorf(\"manifest set invalid, cannot collect namespaces: %w\", err)\n  }\n  return err\n}","preventionTips":["Validate the full manifest set with kubectl dry-run before Visit-based passes","Fix underlying YAML errors first — this error is always a wrapper around a deeper manifest failure","Log the %w cause chain to locate the offending document","Keep render inputs and outputs separated to avoid reprocessing mutated manifests"],"tags":["kubernetes","namespaces","manifest"],"backgroundTag":"yaml-parse-error","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"}