{"record":{"id":"229f9a4cee75fd30","repo":"rtk-ai/rtk","slug":"failed-to-read-stdin","errorCode":null,"errorMessage":"Failed to read stdin: {}","messagePattern":"Failed to read stdin: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/system/pipe_cmd.rs","lineNumber":267,"sourceCode":"        |_| {\n            eprintln!(\"[rtk] warning: filter panicked — passing through raw output\");\n            input.to_string()\n        },\n    )\n}\n\npub fn run(filter_name: Option<&str>, passthrough: bool) -> Result<()> {\n    if passthrough {\n        std::io::copy(&mut std::io::stdin(), &mut std::io::stdout())\n            .map_err(|e| anyhow::anyhow!(\"Failed to relay stdin: {}\", e))?;\n        return Ok(());\n    }\n\n    let mut buf = String::new();\n    std::io::stdin()\n        .take((RAW_CAP + 1) as u64)\n        .read_to_string(&mut buf)\n        .map_err(|e| anyhow::anyhow!(\"Failed to read stdin: {}\", e))?;\n    if buf.len() > RAW_CAP {\n        anyhow::bail!(\"stdin exceeds {} byte limit\", RAW_CAP);\n    }\n\n    let filter_fn = match filter_name {\n        Some(name) => resolve_filter(name).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Unknown filter '{}'. Available: cargo-test, pytest, go-test, go-build, \\\n                 ctest, tsc, vitest, grep, rg, find, fd, git-log, git-diff, git-status, \\\n                 log, mypy, ruff-check, ruff-format, sqlfluff-lint, prettier, phpunit, pest, \\\n                 paratest, php-test, ecs, phpstan, pint\",\n                name\n            )\n        })?,\n        None => auto_detect_filter(&buf),\n    };\n\n    let output = apply_filter(filter_fn, &buf);","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/system/pipe_cmd.rs#L249-L285","documentation":"In non-passthrough mode, `pipe_cmd::run` reads up to RAW_CAP+1 bytes from stdin via `Read::take(...).read_to_string(&mut buf)`. Two failure modes surface here: the read itself errors (mapped to `Failed to read stdin: {}` at line 267), and, if more than RAW_CAP bytes arrived, a subsequent `bail!(\"stdin exceeds {} byte limit\", RAW_CAP)` protects rtk from oversized payloads. Both exist because pipe filters operate on bounded in-memory buffers.","triggerScenarios":"Piping data into `rtk pipe` (without --passthrough) when: (a) stdin read fails (invalid UTF-8 for read_to_string, or an I/O error) → this message; (b) input exceeds the RAW_CAP byte cap → the adjacent size-limit bail. Raised from `pipe_cmd::run` at src/cmds/system/pipe_cmd.rs:267.","commonSituations":"Piping binary data (non-UTF-8) into `rtk pipe`; piping very large files/logs that exceed rtk's stdin byte cap; stdin from a special file or device that errors mid-read; encoding mismatches after locale changes.","solutions":["Ensure input is valid UTF-8 text (e.g. `iconv -f ... -t utf-8` first) — read_to_string fails on invalid bytes.","Reduce input below rtk's stdin size cap: pre-filter/truncate with `head -c`, or use `rtk proxy` for unbounded raw output.","Verify the stdin source is readable (`test -r file` before redirecting) and not a device that errors on read.","If the size limit is the blocker, split input into chunks or process with standard tools instead of `rtk pipe`."],"exampleFix":"// before (shell)\ncat binary.dump | rtk pipe --filter text\n\n// after (shell)\n# decode to UTF-8 and cap size before piping\niconv -f latin1 -t utf-8 binary.dump | head -c 1048576 | rtk pipe --filter text","handlingStrategy":"validation","validationCode":"# check size and UTF-8 before piping into rtk pipe\nsize=$(stat -c%s input.txt)\nlimit=1048576  # match rtk's RAW_CAP\nif [ \"$size\" -gt \"$limit\" ]; then echo \"input too large for rtk pipe\" >&2; exit 1; fi\niconv -f utf-8 -t utf-8 input.txt >/dev/null 2>&1 || { echo \"input is not valid UTF-8\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"if ! rtk pipe --filter text < input.txt; then\n  echo 'fell back: use rtk proxy or split the input' >&2\n  rtk proxy cat input.txt\nfi","preventionTips":["Check input size against rtk's stdin cap before piping.","Convert non-UTF-8 input with iconv/dos2unix first.","Use `rtk proxy` for arbitrarily large or binary payloads.","Sanity-check stdin sources (regular readable files, not devices)."],"tags":["stdin","pipe","io-error","encoding","payload-too-large"],"backgroundTag":"file-read-failed","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}