{"record":{"id":"45a310aad550a0e2","repo":"jdx/mise","slug":"stderr-must-be-piped","errorCode":null,"errorMessage":"stderr must be piped","messagePattern":"stderr must be piped","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd.rs","lineNumber":1562,"sourceCode":"                    Ok(())\n                });\n            }\n        }\n        let mut cp = self\n            .spawn_async_with_etxtbsy_retry()\n            .await\n            .wrap_err_with(|| format!(\"failed to execute command: {self}\"))?;\n        let id = cp.id().unwrap_or_default();\n        let _running_pid = RunningPidGuard::new(cp.id());\n        if let Some(text) = self.stdin.take()\n            && let Some(mut stdin) = cp.stdin.take()\n        {\n            tokio::spawn(async move {\n                let _ = stdin.write_all(text.as_bytes()).await;\n            });\n        }\n        let stdout = cp.stdout.take().expect(\"stdout must be piped\");\n        let stderr = cp.stderr.take().expect(\"stderr must be piped\");\n        let stdout_task = tokio::spawn(read_capped(stdout, max_output_bytes));\n        let stderr_task = tokio::spawn(read_capped(stderr, max_output_bytes));\n        let status = match self.timeout {\n            Some(timeout) => match tokio::time::timeout(timeout, cp.wait()).await {\n                Ok(status) => status?,\n                Err(_) => {\n                    #[cfg(unix)]\n                    signal_process_tree(id, nix::sys::signal::Signal::SIGKILL);\n                    #[cfg(windows)]\n                    kill_process_tree(id);\n                    let _ = cp.wait().await;\n                    bail!(\"timed out after {timeout:?}\");\n                }\n            },\n            None => cp.wait().await?,\n        };\n        let (stdout, stdout_len) = stdout_task.await??;\n        let (stderr, stderr_len) = stderr_task.await??;","sourceCodeStart":1544,"sourceCodeEnd":1580,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/cmd.rs#L1544-L1580","documentation":"The stderr counterpart of the stdout invariant in `read_bounded`: the function captures and bounds both output streams, so the child must have been spawned with `stderr(Stdio::piped())`. If `child.stderr` is `None` at `.take()`, this `.expect(\"stderr must be piped\")` panics, signaling a spawn-configuration bug rather than a runtime condition users can cause.","triggerScenarios":"Command spawned with `stderr(Stdio::inherit())`, `Stdio::null()`, or unset; a code path merging stderr into stdout via `Stdio::piped()` on stdout only; refactors that configure stdio in two places and update only one.","commonSituations":"New callers reuse a command builder configured for passthrough execution; contributor adds a `2>&1`-style merge and forgets the separate stderr pipe expected by `read_bounded`.","solutions":["Add `.stderr(Stdio::piped())` to the command construction before spawn","Keep stdio configuration in one place for commands intended for `read_bounded`/`read_isolated`","Report with `MISE_DEBUG=1` if reproducible on a stock build","Cover the caller with a test that asserts both streams are captured"],"exampleFix":"// before\ncmd.stderr(Stdio::inherit());\n// after\ncmd.stderr(Stdio::piped());","handlingStrategy":"validation","validationCode":"// Before handing a command to output-capturing helpers:\nassert_eq!(cmd.get_stderr(), Stdio::piped(), \"read_bounded requires piped stderr\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pipe both stdout and stderr together for capture helpers","Avoid partial 2>&1-style merges in code that expects separate pipes","Centralize stdio configuration in one builder function"],"tags":["rust","panic","internal-invariant","process","stdio"],"backgroundTag":"internal-invariant-violation","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}