Hmbown/CodeWhale · error · anyhow::Error
GetStdHandle(STD_ERROR_HANDLE) failed
Error message
GetStdHandle(STD_ERROR_HANDLE) failed
What it means
On Windows, GetStdHandle(STD_ERROR_HANDLE) failed while setting up the stderr redirect for runtime logging — the process has no usable standard error handle (e.g. detached console-less context), so redirection cannot proceed.
Source
Thrown at crates/tui/src/runtime_log.rs:322
#[cfg(windows)]
fn redirect_stderr_to(
file: &File,
) -> Result<(
windows::Win32::Foundation::HANDLE,
windows::Win32::Foundation::HANDLE,
)> {
use std::os::windows::io::AsRawHandle;
use windows::Win32::Foundation::{CloseHandle, DUPLICATE_SAME_ACCESS, DuplicateHandle, HANDLE};
use windows::Win32::System::Console::{GetStdHandle, STD_ERROR_HANDLE, SetStdHandle};
use windows::Win32::System::Threading::GetCurrentProcess;
// SAFETY: GetStdHandle is always available; returns INVALID_HANDLE_VALUE
// on failure or null-like handles for console-less processes.
let saved =
unsafe { GetStdHandle(STD_ERROR_HANDLE) }.context("GetStdHandle(STD_ERROR_HANDLE)")?;
if saved.is_invalid() {
return Err(anyhow::anyhow!("GetStdHandle(STD_ERROR_HANDLE) failed"));
}
// Duplicate the file handle so the redirected stderr owns an
// independent HANDLE — mirroring the Unix path's `libc::dup`.
// Without this, `_file` and stderr would alias the same HANDLE;
// a rogue `CloseHandle` on stderr would silently invalidate `_file`.
let raw = HANDLE(file.as_raw_handle());
let process = unsafe { GetCurrentProcess() };
let mut dup = HANDLE::default();
unsafe {
DuplicateHandle(
process,
raw,
process,
&mut dup,
0,
false,
DUPLICATE_SAME_ACCESS,View on GitHub (pinned to 0c42157ee5)
Solutions
- Run the binary from a normal console or redirect context that provides std handles
- Run with stderr redirected to a file
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/tui/src/runtime_log.rs:322 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/3bc6f480a1ba60a6.
Report an issue: GitHub.