{"record":{"id":"ad27012d1fa07de1","repo":"GoogleContainerTools/skaffold","slug":"marshalling-yaml-w","errorCode":null,"errorMessage":"marshalling yaml: %w","messagePattern":"marshalling yaml: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/debugging/transform.go","lineNumber":102,"sourceCode":"\tkind = gvk.Kind\n\tif group == \"\" {\n\t\tdescription = fmt.Sprintf(\"%s/%s\", strings.ToLower(kind), name)\n\t} else {\n\t\tdescription = fmt.Sprintf(\"%s.%s/%s\", strings.ToLower(kind), group, name)\n\t}\n\treturn\n}\n\nfunc applyDebuggingTransforms(l manifest.ManifestList, retriever debug.ConfigurationRetriever, debugHelpersRegistry string) (manifest.ManifestList, error) {\n\tvar updated manifest.ManifestList\n\tfor _, manifest := range l {\n\t\tobj, _, err := decodeFromYaml(manifest, nil, nil)\n\t\tif err != nil {\n\t\t\tlog.Entry(context.Background()).Debugf(\"Unable to interpret manifest for debugging: %v\\n\", err)\n\t\t} else if transformManifest(obj, retriever, debugHelpersRegistry) {\n\t\t\tmanifest, err = encodeAsYaml(obj)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"marshalling yaml: %w\", err)\n\t\t\t}\n\t\t\tif log.IsDebugLevelEnabled() {\n\t\t\t\tlog.Entry(context.Background()).Debugln(\"Applied debugging transform:\\n\", string(manifest))\n\t\t\t}\n\t\t}\n\t\tupdated = append(updated, manifest)\n\t}\n\n\treturn updated, nil\n}\n\n// isPortAvailable returns true if none of the pod's containers specify the given port.\nfunc isPortAvailable(podSpec *v1.PodSpec, port int32) bool {\n\tfor _, container := range podSpec.Containers {\n\t\tfor _, portSpec := range container.Ports {\n\t\t\tif portSpec.ContainerPort == port {\n\t\t\t\treturn false\n\t\t\t}","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/debugging/transform.go#L84-L120","documentation":"applyDebuggingTransforms decodes each Kubernetes manifest from YAML, applies debugging transforms to inject the debugging support containers, and re-encodes the object back to YAML. This error is returned when the mutated object cannot be marshalled back into YAML by encodeAsYaml. It indicates the transformed in-memory Kubernetes object (signature, port, env, annotation fields injected by the debugger retriever) failed json/yaml serialization.","triggerScenarios":"An artifact with debugging support enabled is deployed; decodeFromYaml succeeds but transformManifest returns true (transforms were applied) and encodeAsYaml then fails on the mutated object — e.g. the transform injected a value that the k8s runtime serializer cannot marshal.","commonSituations":"Debugging a container runtarget with an unusual base image where the retrieved debugger config produces non-serializable values; Kubernetes manifest files containing unusual types; a broken/unsupported resource kind that partially decodes and then fails on encode after transformation.","solutions":["Check the wrapped error in the message to identify which field failed to marshal","Verify the manifest decodes cleanly: run the skaffold debug pipeline on a minimal, standard k8s YAML to isolate the offending resource","Update the runtime/serialization dependencies (sigs.k8s.io/yaml, k8s.io/apimachinery) to match the k8s library version Skaffold expects","If only a specific artifact fails, temporarily disable debugging for that artifact (--profile without debug) to confirm the transform is the cause"],"exampleFix":"// before: transform injects a value the encoder chokes on; log and skip the transform\nmanifest, err = encodeAsYaml(obj)\nif err != nil {\n    return nil, fmt.Errorf(\"marshalling yaml: %w\", err)\n}\n// after: fall back to the untransformed manifest\nmanifest, err = encodeAsYaml(obj)\nif err != nil {\n    log.Entry(context.Background()).Warnf(\"skipping debugging transform, encode failed: %v\", err)\n    // keep original manifest\n}","handlingStrategy":"try-catch","validationCode":"// pre-validate the manifest decodes\nvar raw map[string]interface{}\nif err := yaml.Unmarshal([]byte(manifest), &raw); err != nil {\n    return fmt.Errorf(\"manifest is not valid YAML, debugging transform would fail later: %w\", err)\n}","typeGuard":"func isMarshallable(obj runtime.Object) bool {\n    _, err := json.Marshal(obj)\n    return err == nil\n}","tryCatchPattern":"updated, err := debug.ApplyDebuggingTransforms(ctx, manifests, retriever)\nif err != nil {\n    if strings.Contains(err.Error(), \"marshalling yaml\") {\n        log.Warnf(\"debug transform failed on a manifest, continuing untransformed: %v\", err)\n        return originalManifests, nil\n    }\n    return nil, err\n}","preventionTips":["Test debug profiles against all resource kinds in your manifests before CI","Keep the k8s io/apimachinery/sigs.k8s.io/yaml versions aligned with the cluster/generator versions","Validate manifests with `skaffold render --profile=debug` locally before deploying"],"tags":["yaml","kubernetes","debugging","serialization"],"backgroundTag":"yaml-marshalling-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"}