{"record":{"id":"764e7c7b8ba6ed6a","repo":"kubernetes/kops","slug":"error-writing-to-output-v","errorCode":null,"errorMessage":"error writing to output: %v","messagePattern":"error writing to output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cmd/kops/create.go","lineNumber":243,"sourceCode":"\n\t\taddonsClient := clientset.AddonsFor(cluster)\n\n\t\tif err := addonsClient.Replace(addons); err != nil {\n\t\t\treturn fmt.Errorf(\"error writing additional objects: %v\", err)\n\t\t}\n\t}\n\n\t{\n\t\t// If there is a value in this sb, this should mean that we have something to deploy\n\t\t// so let's advise the user how to engage the cloud provider and deploy\n\t\tif sb.String() != \"\" {\n\t\t\tfmt.Fprintf(&sb, \"\\n\")\n\t\t\tfmt.Fprintf(&sb, \"To deploy these resources, run: kops update cluster --name %s --yes\\n\", clusterName)\n\t\t\tfmt.Fprintf(&sb, \"\\n\")\n\t\t}\n\t\t_, err := out.Write(sb.Bytes())\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error writing to output: %v\", err)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":225,"sourceCodeEnd":248,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create.go#L225-L248","documentation":"At the end of RunCreate, the accumulated help text (next-steps instructions in sb) is written to the command's output writer; any Write failure is wrapped as 'error writing to output'. This is purely about emitting user-facing output after the resources were already created.","triggerScenarios":"The io.Writer passed as `out` to RunCreate fails on Write — e.g. a closed/corrupted stdout pipe, full disk when redirecting to a file, or a broken pipe.","commonSituations":"`kops create ... | head` closing the pipe early (EPIPE); redirecting output to a file on a full filesystem; running kops in a container with a closed stdout.","solutions":["Re-run the command without truncating consumers (avoid piping into `head` without handling SIGPIPE)","Check disk space if output is redirected to a file","Ensure stdout/stderr are valid open file descriptors in the execution environment","Note the resources were already created; only the help output was lost"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure output destination is writable\nf, err := os.OpenFile(outPath, os.O_WRONLY|os.O_CREATE, 0644)\nif err != nil { return err }\nif err := f.Close(); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if _, err := out.Write(sb.Bytes()); err != nil {\n\tif errors.Is(err, syscall.EPIPE) {\n\t\t// downstream consumer closed; safe to ignore or log\n\t}\n\treturn fmt.Errorf(\"error writing to output: %w\", err)\n}","preventionTips":["Avoid piping kops output into short-lived consumers like head","Check free disk space when redirecting output","Run kops in an environment with valid stdout/stderr"],"tags":["cli","io","output"],"backgroundTag":"broken-pipe-write-failure","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}