Hmbown/CodeWhale · error · anyhow::Error
SetStdHandle(STD_ERROR_HANDLE) failed: {e}
Error message
SetStdHandle(STD_ERROR_HANDLE) failed: {e} What it means
On Windows, SetStdHandle(STD_ERROR_HANDLE) rejected the duplicated handle during the stderr redirect, so the runtime log cannot capture stderr; the duplicated handle is closed to avoid a leak and the original remains untouched.
Source
Thrown at crates/tui/src/runtime_log.rs:350
unsafe {
DuplicateHandle(
process,
raw,
process,
&mut dup,
0,
false,
DUPLICATE_SAME_ACCESS,
)
.context("DuplicateHandle for stderr redirect")?;
}
// SAFETY: SetStdHandle redirects stderr to the duplicated handle.
// We save the original handle so the guard can restore it on drop.
unsafe {
if let Err(e) = SetStdHandle(STD_ERROR_HANDLE, dup) {
let _ = CloseHandle(dup);
return Err(anyhow::anyhow!(
"SetStdHandle(STD_ERROR_HANDLE) failed: {e}"
));
}
}
Ok((saved, dup))
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs::FileTimes;
#[test]
fn whitespace_home_override_is_consistent_across_tui_state_entry_points() {
let _lock = crate::test_support::lock_test_env();
let tmp = tempfile::TempDir::new().expect("temporary root");
let home = tmp.path().join("home");
let userprofile = tmp.path().join("userprofile");View on GitHub (pinned to 0c42157ee5)
Solutions
- Run without the stderr redirect/log-file option
- Check that no other mechanism is replacing std handles concurrently
- Report with the Windows error code in {e}
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/tui/src/runtime_log.rs:350 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/2d3b8462c6b102fb.
Report an issue: GitHub.