{"record":{"id":"0de75a8189b7a70a","repo":"kubernetes/kops","slug":"writing-output-v","errorCode":null,"errorMessage":"writing output: %v","messagePattern":"writing output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_secrets.go","lineNumber":162,"sourceCode":"\tcase OutputYaml:\n\t\treturn fmt.Errorf(\"yaml output format is not (currently) supported for secrets\")\n\tcase OutputJSON:\n\t\treturn fmt.Errorf(\"json output format is not (currently) supported for secrets\")\n\tcase \"plaintext\":\n\t\tfor _, item := range items {\n\t\t\tvar data string\n\t\t\tsecret, err := secretStore.FindSecret(item)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"getting secret %q: %v\", item, err)\n\t\t\t}\n\t\t\tif secret == nil {\n\t\t\t\treturn fmt.Errorf(\"cannot find secret %q\", item)\n\t\t\t}\n\t\t\tdata = string(secret.Data)\n\n\t\t\t_, err = fmt.Fprintf(out, \"%s\\n\", data)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"writing output: %v\", err)\n\t\t\t}\n\t\t}\n\t\treturn nil\n\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown output format: %q\", options.Output)\n\t}\n}\n","sourceCodeStart":144,"sourceCodeEnd":171,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_secrets.go#L144-L171","documentation":"In kOps' `kops get secrets` command, after fetching a secret from the keyStore the raw data is printed to the command output with fmt.Fprintf. If that write fails (e.g. the output stream was closed, or a file-backed writer hit an I/O error), the command wraps the underlying error as \"writing output: %v\" and aborts RunGetSecrets.","triggerScenarios":"Running `kops get secrets <name> -o text` where the underlying writer `out` (stdout piped to a closed process such as `| head`, or a file with a full disk / permission problem) returns an error from Fprintf.","commonSituations":"Piping output into `head` or `less` which closes the pipe early (EPIPE); redirecting to a file on a full disk; running in an environment where stdout is closed.","solutions":["Check the downstream consumer of the pipe: re-run without `| head`/`| less`, or use `kops get secrets ... | cat`","Verify disk space and write permissions on the redirect target (df -h, ls -l)","Check the wrapped error text after 'writing output:' for the actual cause (broken pipe vs permission denied)","If piping is intentional, ignore EPIPE: run `kops get secrets ... || true` or use set -o pipefail awareness in scripts"],"exampleFix":"// before\n_, err = fmt.Fprintf(out, \"%s\\n\", data)\nif err != nil {\n\treturn fmt.Errorf(\"writing output: %v\", err)\n}\n// after\n_, err = fmt.Fprintf(out, \"%s\\n\", data)\nif err != nil {\n\tif errors.Is(err, syscall.EPIPE) {\n\t\treturn nil // consumer closed the pipe; not a real failure\n\t}\n\treturn fmt.Errorf(\"writing output: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"# ensure output target is writable before running\nout=/path/to/out.txt; [ -w \"$(dirname \"$out\")\" ] || { echo \"unwritable output dir\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := runGetSecrets(opts); err != nil {\n\tvar werr error\n\tif strings.HasPrefix(err.Error(), \"writing output:\") && strings.Contains(err.Error(), \"broken pipe\") {\n\t\t// tolerate EPIPE from early-closing consumers\n\t\treturn nil\n\t}\n\treturn err\n}","preventionTips":["Avoid piping kops output into head/less; pipe to cat or a file first","Check disk space before redirecting large outputs","Inspect the text after 'writing output:' to identify the OS-level cause"],"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"}