{"record":{"id":"6bd36c8018b346c0","repo":"kubernetes/kops","slug":"encoding-resources-for-v-w","errorCode":null,"errorMessage":"encoding resources for %v: %w","messagePattern":"encoding resources for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/resourcedumper.go","lineNumber":259,"sourceCode":"\t\t\t\terr: fmt.Errorf(\"marshaling to json for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch d.output {\n\t\tcase \"yaml\":\n\t\t\tcontents, err = yaml.JSONToYAML(contents)\n\t\t\tif err != nil {\n\t\t\t\tresults <- resourceDumpResult{\n\t\t\t\t\terr: fmt.Errorf(\"marshaling to yaml for %v: %w\", job, err),\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\t_, err = resFile.Write(contents)\n\t\tif err != nil {\n\t\t\tresults <- resourceDumpResult{\n\t\t\t\terr: fmt.Errorf(\"encoding resources for %v: %w\", job, err),\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tresults <- resourceDumpResult{}\n\t}\n}\n\nfunc maskObject(obj runtime.Object) error {\n\tif obj.GetObjectKind().GroupVersionKind() == (schema.GroupVersionKind{Group: \"\", Version: \"v1\", Kind: \"Secret\"}) {\n\t\tunstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdata, ok, err := unstructured.NestedMap(unstructuredObj, \"data\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting data from secret: %w\", err)\n\t\t}\n\t\tif ok {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/resourcedumper.go#L241-L277","documentation":"This error wraps a failed os.File.Write when kops writes a serialized resource dump (JSON or YAML) to a file in the artifacts directory during a cluster dump. It is thrown by dumpGVRNamespaces after the resource list has been marshaled successfully but the bytes could not be written to disk. The wrapped %w error carries the underlying filesystem failure (disk full, permissions, closed file, I/O error).","triggerScenarios":"The worker goroutine in dumpGVRNamespaces has created resFile via os.Create and, after marshaling the resource list (and optionally converting to YAML), resFile.Write(contents) returns a non-nil error. Causes include a full disk, the artifacts directory/file being removed mid-dump, insufficient write permissions, or an EIO on the backing volume.","commonSituations":"Running `kops get -o yaml --full` or `kops toolbox dump` on a node with a full disk; dumping to an artifactsDir on a volume that gets unmounted during the dump; running kops as a user without write permission to the artifacts directory; large cluster dumps exhausting disk space mid-write.","solutions":["Check free disk space on the filesystem holding the artifacts directory (df -h) and free space or redirect the dump to a volume with room for the full dump.","Verify the process user has write permission on the artifacts directory (ls -ld <artifactsDir>) and rerun with corrected permissions or a different directory.","Confirm the artifacts volume is mounted and stable for the duration of the dump; re-run the dump after remounting.","Inspect the wrapped error (the %w cause) with errors.Unwrap or %v of the returned error for the exact syscall failure (ENOSPC, EACCES, EIO) and address it accordingly."],"exampleFix":"// before: writing dump contents without checking for partial writes or syncing\n_, err = resFile.Write(contents)\nif err != nil {\n    results <- resourceDumpResult{err: fmt.Errorf(\"encoding resources for %v: %w\", job, err)}\n}\n// after: pre-check disk capacity / log the wrapped cause to diagnose ENOSPC quickly\nif stat, statErr := os.Stat(path.Dir(resPath)); statErr != nil || stat == nil {\n    klog.Warningf(\"artifacts dir %q unavailable before write: %v\", path.Dir(resPath), statErr)\n}\nif _, err = resFile.Write(contents); err != nil {\n    results <- resourceDumpResult{err: fmt.Errorf(\"encoding resources for %v: %w\", job, err)}\n}","handlingStrategy":"try-catch","validationCode":"// before dumping, ensure the artifacts dir is writable and has headroom\ninfo, err := os.Stat(artifactsDir)\nif err != nil || !info.IsDir() {\n    return fmt.Errorf(\"artifacts dir %q missing: %w\", artifactsDir, err)\n}\nprobe, err := os.CreateTemp(artifactsDir, \".writecheck\")\nif err != nil {\n    return fmt.Errorf(\"artifacts dir %q not writable: %w\", artifactsDir, err)\n}\nprobe.Close()\nos.Remove(probe.Name())","typeGuard":null,"tryCatchPattern":"// each resourceDumpResult carries an error; collect and inspect the wrapped cause\nfor r := range results {\n    if r.err != nil {\n        var pathErr *fs.PathError\n        if errors.As(r.err, &pathErr) {\n            klog.Errorf(\"dump write failed on %s: %v (op=%s, path=%s)\", pathErr.Err, pathErr.Op, pathErr.Path)\n        } else {\n            klog.Errorf(\"dump failed: %v\", r.err)\n        }\n    }\n}","preventionTips":["Check disk space on the artifacts filesystem before starting large dumps.","Run the dump as a user with write access to the artifacts directory.","Avoid dumping to network/removable volumes that may unmount mid-run.","Log errors.Unwrap of the failure to distinguish ENOSPC vs EACCES vs EIO quickly."],"tags":["filesystem","dump","io","kops"],"backgroundTag":"disk-full-write-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}