{"record":{"id":"a6e4616b556de805","repo":"kubernetes/kops","slug":"error-writing-to-stdout-v-a6e461","errorCode":null,"errorMessage":"error writing to stdout: %v","messagePattern":"error writing to stdout: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/toolbox_dump.go","lineNumber":305,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating pod log dumper: %w\", err)\n\t\t\t}\n\t\t\tif err := logDumper.DumpLogs(ctx); err != nil {\n\t\t\t\tklog.Warningf(\"error dumping pod logs: %v\", err)\n\t\t\t}\n\t\t}\n\t}\n\n\tif cloudResources != nil {\n\t\tswitch options.Output {\n\t\tcase OutputYaml:\n\t\t\tb, err := kops.ToRawYaml(cloudResources)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error marshaling yaml: %v\", err)\n\t\t\t}\n\t\t\t_, err = out.Write(b)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\n\t\tcase OutputJSON:\n\t\t\tb, err := json.MarshalIndent(cloudResources, \"\", \"  \")\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error marshaling json: %v\", err)\n\t\t\t}\n\t\t\t_, err = out.Write(b)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n\t\t\t}\n\t\t\treturn nil\n\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"unsupported output format: %q\", options.Output)\n\t\t}\n\t}","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/toolbox_dump.go#L287-L323","documentation":"After successfully marshaling the dump to YAML, the command writes the bytes to the out writer (stdout). This error means that write failed. It is an I/O error, not a data error — the dump data itself was fine.","triggerScenarios":"Running `kops toolbox dump -o yaml` when the process stdout is closed, the pipe consumer exited (e.g. `| head` closed the pipe), or the output device returned an error (ENOSPC, EPIPE, bad fd).","commonSituations":"Piping into `head` or a grep that exits early; writing to a full disk via redirection; running in an environment with a broken/closed stdout.","solutions":["Check the receiving end of the pipe did not exit early (avoid piping into commands that close early, or use `set -o pipefail` carefully)","Verify disk space if redirecting to a file","Rerun and write to a file: kops toolbox dump -o yaml > dump.yaml"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check stdout is writable\nif f, ok := out.(*os.File); ok {\n\tif _, err := f.Stat(); err != nil {\n\t\treturn fmt.Errorf(\"stdout unavailable: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"_, err = out.Write(b)\nif err != nil {\n\tvar se *os.SyscallError\n\tif errors.As(err, &se) && errors.Is(se.Err, syscall.EPIPE) {\n\t\t// downstream consumer closed the pipe; not fatal for the data\n\t}\n\treturn fmt.Errorf(\"error writing to stdout: %v\", err)\n}","preventionTips":["Avoid piping kops output into commands that exit early (use full output or a file)","Redirect to a file when disk space is uncertain after checking `df`","Use `cmd1 | cmd2 || true` carefully in scripts consuming dumps"],"tags":["cli","io","stdout","dump"],"backgroundTag":"broken-pipe","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"}