GoogleContainerTools/skaffold · error
collecting namespaces: %w
Error message
collecting namespaces: %w
What it means
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'.
Source
Thrown at pkg/skaffold/kubernetes/manifest/namespaces.go:45
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/warnings"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/yaml"
)
const namespaceField = "namespace"
const defaultNamespace = "default"
// CollectNamespaces returns all the namespaces in the manifests.
func (l *ManifestList) CollectNamespaces() ([]string, error) {
replacer := newNamespaceCollector()
// TODO(aaron-prindle) make sure this is ok?
rs := &ResourceSelectorImages{}
if _, err := l.Visit(replacer, rs); err != nil {
// if _, err := l.Visit(replacer, make(map[schema.GroupKind]latest.ResourceFilter), make(map[schema.GroupKind]latest.ResourceFilter)); err != nil {
// TODO(aaron-prindle) verify this doesn't need to support allow/deny list, also see if 'nil' is better option for unused inputs
return nil, fmt.Errorf("collecting namespaces: %w", err)
}
namespaces := make([]string, 0, len(replacer.namespaces))
for ns := range replacer.namespaces {
namespaces = append(namespaces, ns)
}
sort.Strings(namespaces)
return namespaces, nil
}
type namespaceCollector struct {
namespaces map[string]bool
}
func newNamespaceCollector() *namespaceCollector {
return &namespaceCollector{
namespaces: map[string]bool{},
}View on GitHub (pinned to a1189de023)
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
Example fix
// before: tabs break YAML parsing inside Visit spec: replicas: 1 // after spec: replicas: 1
Defensive patterns
Strategy: try-catch
Validate before calling
import "gopkg.in/yaml.v3"
func validateAll(manifests [][]byte) error {
for _, m := range manifests {
var v interface{}
if err := yaml.Unmarshal(m, &v); err != nil { return fmt.Errorf("invalid manifest %q: %w", m, err) }
}
return nil
}
// run before CollectNamespaces Try / catch
ns, err := manifests.CollectNamespaces()
if err != nil {
if strings.Contains(err.Error(), "collecting namespaces") {
// the wrapped cause identifies the bad manifest; log it and abort or skip
return fmt.Errorf("manifest set invalid, cannot collect namespaces: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Broken manifests produced by an upstream render step propagating as a namespace-collection failure; manifests referencing malformed CRDs or empty documents.
Related errors
- empty file found at path: %s, verify that the manifest path
- resource found in %s is not a k8s job, verify the manifest p
- found existing node affinity for os/arch: %s
- unmarshaling config: %w
- error converting %s to map[string]interface{}
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/baf8424ffc82425f.
Report an issue: GitHub.