{"record":{"id":"d2dcf7df207f250f","repo":"denoland/deno","slug":"setstdhandle-failed-error","errorCode":null,"errorMessage":"SetStdHandle failed (error {})","messagePattern":"SetStdHandle failed \\(error (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/util/windows.rs","lineNumber":255,"sourceCode":"          lpSecurityDescriptor: std::ptr::null_mut(),\n          bInheritHandle: TRUE,\n        };\n        let file_handle = CreateFileA(\n          c\"\\\\\\\\?\\\\NUL\".as_ptr() as *const u8,\n          desired_access,\n          FILE_SHARE_READ | FILE_SHARE_WRITE,\n          &security_attributes,\n          OPEN_EXISTING,\n          FILE_ATTRIBUTE_NORMAL,\n          std::ptr::null_mut(),\n        );\n        if file_handle == INVALID_HANDLE_VALUE {\n          panic!(\"Could not open NUL device (error {})\", GetLastError());\n        }\n\n        // Assign the opened NUL handle to the missing stdio handle.\n        if SetStdHandle(std_handle, file_handle) == FALSE {\n          panic!(\"SetStdHandle failed (error {})\", GetLastError());\n        }\n      }\n    }\n  }\n}\n","sourceCodeStart":237,"sourceCodeEnd":261,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/util/windows.rs#L237-L261","documentation":"The final step of Deno's Windows stdio repair: after successfully opening \\\\?\\NUL, it calls SetStdHandle to install that handle as the missing standard stream. If the assignment fails, the process would run with inconsistent stdio, so Deno panics with the last Win32 error. Like the other stdio-repair panics, it reflects a broken process environment rather than anything in user code.","triggerScenarios":"Same precondition as the NUL-open failure (a closed stdio slot) plus a SetStdHandle failure — handle table corruption, security software intercepting handle mutation, or unusual container/sandbox layers restricting handle operations on Windows.","commonSituations":"Deno spawned inside sandboxed CI runners or job objects that restrict handle mutation; rare enough that a reboot or a different launch method (explicit redirection) usually clears it.","solutions":["Redirect stdio explicitly in the launching command so the repair path is never attempted","Reboot to reset kernel handle state","Test outside the sandbox/EDR layer; add exclusions if that resolves it","Report with the error code if reproducible on the latest Deno"],"exampleFix":":: before — rely on deno repairing a closed stdio slot\ndeno run app.ts\n\n:: after — explicit redirection avoids the repair entirely\ndeno run app.ts < NUL > out.log 2>&1","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Explicit stdio redirection avoids the entire stdio-repair path","Test the same command outside sandboxes/job objects to identify restricted-handle environments","Report persistent SetStdHandle failures with the decoded error code"],"tags":["windows","stdio","setstdhandle","startup"],"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"}