{"record":{"id":"2d3b8462c6b102fb","repo":"Hmbown/CodeWhale","slug":"setstdhandle-std-error-handle-failed-e","errorCode":null,"errorMessage":"SetStdHandle(STD_ERROR_HANDLE) failed: {e}","messagePattern":"SetStdHandle\\(STD_ERROR_HANDLE\\) failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_log.rs","lineNumber":350,"sourceCode":"    unsafe {\n        DuplicateHandle(\n            process,\n            raw,\n            process,\n            &mut dup,\n            0,\n            false,\n            DUPLICATE_SAME_ACCESS,\n        )\n        .context(\"DuplicateHandle for stderr redirect\")?;\n    }\n\n    // SAFETY: SetStdHandle redirects stderr to the duplicated handle.\n    // We save the original handle so the guard can restore it on drop.\n    unsafe {\n        if let Err(e) = SetStdHandle(STD_ERROR_HANDLE, dup) {\n            let _ = CloseHandle(dup);\n            return Err(anyhow::anyhow!(\n                \"SetStdHandle(STD_ERROR_HANDLE) failed: {e}\"\n            ));\n        }\n    }\n    Ok((saved, dup))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use std::fs::FileTimes;\n\n    #[test]\n    fn whitespace_home_override_is_consistent_across_tui_state_entry_points() {\n        let _lock = crate::test_support::lock_test_env();\n        let tmp = tempfile::TempDir::new().expect(\"temporary root\");\n        let home = tmp.path().join(\"home\");\n        let userprofile = tmp.path().join(\"userprofile\");","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/runtime_log.rs#L332-L368","documentation":"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.","triggerScenarios":"Thrown at crates/tui/src/runtime_log.rs:350 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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}"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}