{"record":{"id":"4034d3acd8ed6cce","repo":"gastownhall/beads","slug":"reading-from-stdin-w","errorCode":null,"errorMessage":"reading from stdin: %w","messagePattern":"reading from stdin: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/flags.go","lineNumber":255,"sourceCode":"// one (echo, heredocs) — while file content is passed through verbatim like\n// every other file-input flag. Returns \"\" with provided=false when no source\n// is given at all.\nfunc textFromSources(src textSources) (text string, provided bool, err error) {\n\ttype source struct {\n\t\tname    string\n\t\tresolve func() (string, error)\n\t}\n\tvar sources []source\n\tif positional := strings.Join(src.positional, \" \"); strings.TrimSpace(positional) != \"\" {\n\t\tsources = append(sources, source{fmt.Sprintf(\"positional text %q\", positional), func() (string, error) {\n\t\t\treturn positional, nil\n\t\t}})\n\t}\n\tif src.stdin != nil {\n\t\tsources = append(sources, source{\"--stdin\", func() (string, error) {\n\t\t\tcontent, err := io.ReadAll(src.stdin)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"reading from stdin: %w\", err)\n\t\t\t}\n\t\t\treturn strings.TrimRight(string(content), \"\\r\\n\"), nil\n\t\t}})\n\t}\n\tif src.filePath != \"\" {\n\t\tsources = append(sources, source{\"--file\", func() (string, error) {\n\t\t\t// Verbatim, like every other file-input flag (--body-file,\n\t\t\t// --design-file, --reason-file): a file is a deliberate payload,\n\t\t\t// so its trailing newlines are preserved.\n\t\t\treturn readBodyFile(src.filePath)\n\t\t}})\n\t}\n\tif src.flagSet || src.flagText != \"\" {\n\t\tsources = append(sources, source{src.flagName, func() (string, error) {\n\t\t\treturn src.flagText, nil\n\t\t}})\n\t}\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/flags.go#L237-L273","documentation":"This error wraps a failure that occurred while reading all bytes from the process's stdin stream when a command was invoked with the --stdin flag. It is produced by textFromSources in cmd/bd/flags.go, which collects text from registered sources (--stdin, --file, positional args). The underlying read error (wrapped with %w) usually indicates the stdin stream itself failed (I/O error, closed/broken pipe, or a non-readable stdin), not that the content was invalid.","triggerScenarios":"Running a bd command with --stdin where io.ReadAll(os.Stdin) returns an error, e.g. stdin is closed by the parent process, a pipe breaks (upstream command exited), or an I/O error occurs on a redirected file descriptor.","commonSituations":"Piping from a command that failed mid-stream (e.g. `some-cmd | bd create --stdin` where some-cmd crashed); running in environments with no usable stdin (CI jobs, detached processes, daemons); redirecting stdin from an unreadable or deleted file.","solutions":["Check the wrapped cause (%w) to identify the actual stdin I/O failure and fix the upstream producer or pipe.","Verify stdin is available and connected: pipe content explicitly (echo \"text\" | bd ... --stdin) instead of relying on inherited stdin.","In scripts/CI, redirect stdin explicitly from a file: bd ... --stdin < input.txt.","If stdin may be absent, pass the text positionally or via --file instead of --stdin."],"exampleFix":"// before\ncat notes.txt | bd create \"title\" --stdin   # fails if cat fails mid-stream\n// after\nbd create \"title\" --stdin < notes.txt       # explicit, fail-fast redirect","handlingStrategy":"try-catch","validationCode":"// ensure stdin has data before piping\nif [ -t 0 ]; then echo \"no stdin provided\" >&2; exit 1; fi","typeGuard":null,"tryCatchPattern":"// Go-style wrap inspection (bd source behavior)\nif _, err := textFromSources(...); err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) { /* handle stdin I/O failure */ }\n    return fmt.Errorf(\"stdin input failed: %w\", err)\n}","preventionTips":["Redirect stdin explicitly from a file rather than relying on inherited descriptors.","Check upstream pipeline commands for failure (set -o pipefail in bash).","In CI, always provide explicit stdin or use --file instead.","Avoid invoking --stdin from detached/daemonized processes."],"tags":["cli","stdin","io"],"backgroundTag":"stdin-read-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}