{"record":{"id":"b2b02bbfd9d98063","repo":"kubernetes/kops","slug":"error-reading-stdin-v","errorCode":null,"errorMessage":"error reading stdin: %v","messagePattern":"error reading stdin: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/root.go","lineNumber":408,"sourceCode":"\t\treturn nil, nil, completions, directive\n\t}\n\n\tclientSet, err = factory.KopsClient()\n\tif err != nil {\n\t\tcompletions, directive := commandutils.CompletionError(\"getting clientset\", err)\n\t\treturn nil, nil, completions, directive\n\t}\n\n\treturn cluster, clientSet, nil, 0\n}\n\n// ConsumeStdin reads all the bytes available from stdin\nfunc ConsumeStdin() ([]byte, error) {\n\tfile := os.Stdin\n\tbuf := new(bytes.Buffer)\n\t_, err := buf.ReadFrom(file)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading stdin: %v\", err)\n\t}\n\treturn buf.Bytes(), nil\n}\n","sourceCodeStart":390,"sourceCodeEnd":412,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/root.go#L390-L412","documentation":"ConsumeStdin reads all bytes from os.Stdin and wraps any read failure in this error. It is used by commands that accept resources (cluster/instancegroup/secret definitions) via heredocs or pipes. A failure means the stdin stream itself could not be read (I/O error), not that the content was invalid.","triggerScenarios":"buf.ReadFrom(os.Stdin) returns an error — e.g. stdin is closed unexpectedly, a pipe breaks, or an I/O device error occurs while commands like kops create, replace, delete, or create secret consume piped/heredoc input.","commonSituations":"Piping from a command that failed or closed the pipe early (broken pipe); redirecting from an unreadable file descriptor; running in an environment without a valid stdin (detached CI jobs, some IDE terminals); using </dev/null when a definition was expected on stdin.","solutions":["Check the command producing the pipe for its own failure (the upstream process may have died mid-stream).","Ensure the shell environment has a usable stdin; avoid running inside sandboxes that close fd 0.","Write the resource to a file and use -f instead of piping to stdin.","Retry the command; transient pipe/EOF conditions usually disappear on a clean re-run."],"exampleFix":"// before\nkops create -f - < /dev/null   # stdin closed -> error reading stdin\n// after\nkops create -f cluster.yaml\n# or correctly: cat cluster.yaml | kops create -f -","handlingStrategy":"try-catch","validationCode":"if [ ! -t 0 ] && [ ! -p /dev/stdin ] && [ ! -f \"$RESOURCE_FILE\" ]; then echo \"no stdin or file input\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"data, err := ConsumeStdin()\nif err != nil {\n    return fmt.Errorf(\"failed to read resource from stdin (is the pipe source healthy?): %w\", err)\n}","preventionTips":["Prefer -f <file> over piping in scripts so failures are attributable","Check upstream pipeline commands with pipefail (set -o pipefail)","Avoid running kops in environments with closed stdin (some CI detached steps)","Test the pipe source alone: cat resource.yaml | head -1"],"tags":["kops","stdin","io"],"backgroundTag":"stdin-read-failure","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"}