{"record":{"id":"b1d8afd2ebd1f5b7","repo":"denoland/deno","slug":"gethandleinformation-failed-error","errorCode":null,"errorMessage":"GetHandleInformation failed (error {})","messagePattern":"GetHandleInformation failed \\(error (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/util/windows.rs","lineNumber":223,"sourceCode":"    use windows_sys::Win32::Storage::FileSystem::OPEN_EXISTING;\n    use windows_sys::Win32::System::Console::GetStdHandle;\n    use windows_sys::Win32::System::Console::STD_ERROR_HANDLE;\n    use windows_sys::Win32::System::Console::STD_INPUT_HANDLE;\n    use windows_sys::Win32::System::Console::STD_OUTPUT_HANDLE;\n    use windows_sys::Win32::System::Console::SetStdHandle;\n\n    for std_handle in [STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {\n      // Check whether stdio handle is open.\n      let handle = GetStdHandle(std_handle);\n      let is_valid = if handle.is_null() || handle == INVALID_HANDLE_VALUE {\n        false\n      } else {\n        // The stdio handle is open; check whether its handle is valid.\n        let mut flags: u32 = 0;\n        match GetHandleInformation(handle, &mut flags) {\n          FALSE if GetLastError() == ERROR_INVALID_HANDLE => false,\n          FALSE => {\n            panic!(\"GetHandleInformation failed (error {})\", GetLastError());\n          }\n          _ => true,\n        }\n      };\n\n      if !is_valid {\n        // Open NUL device.\n        let desired_access = match std_handle {\n          STD_INPUT_HANDLE => FILE_GENERIC_READ,\n          _ => FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES,\n        };\n        let security_attributes = SECURITY_ATTRIBUTES {\n          nLength: size_of::<SECURITY_ATTRIBUTES>() as u32,\n          lpSecurityDescriptor: std::ptr::null_mut(),\n          bInheritHandle: TRUE,\n        };\n        let file_handle = CreateFileA(\n          c\"\\\\\\\\?\\\\NUL\".as_ptr() as *const u8,","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/util/windows.rs#L205-L241","documentation":"During early startup on Windows, Deno probes stdin/stdout/stderr with GetStdHandle + GetHandleInformation to detect closed handles and substitute the NUL device. If GetHandleInformation fails with any error other than ERROR_INVALID_HANDLE, the handle state is too broken to recover from and Deno panics with the raw Win32 error code. It means a handle exists but its flags cannot be queried (access denied, bogus inherited handle).","triggerScenarios":"Launching `deno` from a parent that passes broken or pseudo stdio handles: Windows services, Task Scheduler, git hooks, CI agents, or hand-rolled CreateProcess callers that close or redirect stdio incorrectly; also security software intercepting handle queries.","commonSituations":"Running Deno as a scheduled task or service without explicit stdio redirection; spawning Deno from another program with closed handle slots; antivirus/EDR interference on Windows.","solutions":["Launch Deno from a normal console to verify it works there","When spawning Deno programmatically, always pass explicit stdin/stdout/stderr (pipe, file, or NUL) instead of inheriting broken handles","Use explicit redirection in service contexts: `deno run app.ts < NUL > deno.log 2>&1`","Translate the reported code with `net helpmsg <code>` to identify which handle/query failed; report to denoland/deno if it persists on the latest version"],"exampleFix":":: before — scheduler/service launches deno with broken inherited stdio\ndeno run app.ts\n\n:: after — every stream gets a valid target\ndeno run app.ts < NUL > deno.log 2>&1","handlingStrategy":"validation","validationCode":"// Rust parent: never leave deno with broken inherited handles\nuse std::process::{Command, Stdio};\nCommand::new(\"deno\")\n  .args([\"run\", \"app.ts\"])\n  .stdin(Stdio::null())\n  .stdout(Stdio::piped())\n  .stderr(Stdio::piped())\n  .spawn()?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass explicit stdio (pipe/file/NUL) when spawning Deno from services, schedulers, or CI agents","Avoid launching Deno with closed inherited handle slots","Note the Win32 code in the message and decode it with `net helpmsg <code>` before reporting"],"tags":["windows","stdio","win32","startup","gethandleinformation"],"backgroundTag":"win32-stdio-initialization-failed","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}