{"record":{"id":"bfb085aec69a82db","repo":"GoogleContainerTools/skaffold","slug":"deleting-files-w-bfb085","errorCode":null,"errorMessage":"deleting files: %w","messagePattern":"deleting files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/sync.go","lineNumber":319,"sourceCode":"\t\treturn fmt.Errorf(\"post-sync hooks failed for artifact %q: %w\", item.Artifact.ImageName, err)\n\t}\n\treturn nil\n}\n\nfunc (s *PodSyncer) sync(ctx context.Context, item *Item) error {\n\tif len(item.Copy) > 0 {\n\t\tlog.Entry(ctx).Info(\"Copying files:\", item.Copy, \"to\", item.Image)\n\n\t\tif err := Perform(ctx, item.Image, item.Copy, s.copyFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {\n\t\t\treturn fmt.Errorf(\"copying files: %w\", err)\n\t\t}\n\t}\n\n\tif len(item.Delete) > 0 {\n\t\tlog.Entry(ctx).Info(\"Deleting files:\", item.Delete, \"from\", item.Image)\n\n\t\tif err := Perform(ctx, item.Image, item.Delete, s.deleteFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting files: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, syncMap) *exec.Cmd, namespaces []string, kubeContext string) error {\n\tif len(files) == 0 {\n\t\treturn nil\n\t}\n\n\terrs, ctx := errgroup.WithContext(ctx)\n\n\tclient, err := kubernetesclient.Client(kubeContext)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting Kubernetes client: %w\", err)\n\t}\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/sync.go#L301-L337","documentation":"Wraps failures from performing file deletion on a running Kubernetes pod/container during dev-loop file sync. When Skaffold detects deleted files and tries to remove them from the deployed container via `Perform` with the deleteFileFn, any underlying failure (kubectl exec or pod lookup failure) is wrapped with this message. It indicates sync's delete phase failed, not the build or deploy.","triggerScenarios":"`SyncWorkflow`/`sync.Sync` is called with an item whose `item.Delete` is non-empty and `Perform(ctx, item.Image, item.Delete, s.deleteFileFn, namespaces, kubeContext)` returns an error — e.g. the target pod disappeared, the container command to rm files failed, or the Kubernetes client could not be created.","commonSituations":"Pod restarted or was deleted between change detection and sync; wrong/inaccessible kubeContext; namespace has no running pods; container image lacks a shell or the rm command fails; RBAC prevents listing pods.","solutions":["Inspect the wrapped cause (%w) below this message — fix the underlying kubectl/pod error it reports","Verify the pod running the image is up and Running (`kubectl get pods -n <ns>`); retrigger sync after the pod is ready","Check the kubeContext (--kube-context) and that kubectl can reach the cluster","Confirm RBAC allows listing pods and exec into pods in the target namespaces"],"exampleFix":"// before: pod scaled to 0 causes delete failure\nskaffold dev --kube-context stale-context\n// after\nkubectl config use-context dev-cluster\nskaffold dev","handlingStrategy":"try-catch","validationCode":"// before triggering sync, verify pods are reachable\npods, _ := kubeClient.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{FieldSelector: \"status.phase=Running\"})\nif len(pods.Items) == 0 { return errors.New(\"no running pods; skip delete sync\") }","typeGuard":"if item.Delete == nil || len(item.Delete) == 0 { return nil }","tryCatchPattern":"if err := syncer.Sync(ctx, out, item); err != nil {\n    var delErr error\n    if strings.Contains(err.Error(), \"deleting files:\") {\n        delErr = errors.Unwrap(err) // inspect underlying kubectl/pod error\n    }\n    log.Warnf(\"delete sync skipped: %v\", delErr)\n}","preventionTips":["Keep the kubeContext valid and reachable before starting skaffold dev","Re-sync only when pods are Running (rollout status)","Avoid scaling pods to zero during the dev loop","Grant pods/list + exec RBAC in target namespaces"],"tags":["kubernetes","file-sync","dev-loop"],"backgroundTag":"file-sync-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"}