{"record":{"id":"b0367fd71ab50560","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-create-hidden-window-err","errorCode":null,"errorMessage":"Failed to create hidden window: {err}","messagePattern":"Failed to create hidden window: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/tauri/src/shutdown_hook.rs","lineNumber":163,"sourceCode":"    let hidden_window = unsafe {\n        CreateWindowExW(\n            WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE,\n            class_name.as_ptr(),\n            window_name.as_ptr(),\n            0,\n            0,\n            0,\n            0,\n            0,\n            std::ptr::null_mut(),\n            std::ptr::null_mut(),\n            h_instance,\n            std::ptr::null_mut(),\n        )\n    };\n    if hidden_window.is_null() {\n        let err = Error::from_win32();\n        anyhow::bail!(\"Failed to create hidden window: {err}\");\n    }\n\n    let window_handle = WindowHandle {\n        hwnd: hidden_window,\n        h_instance,\n    };\n\n    if let Err(e) = initd_tx.send(()) {\n        anyhow::bail!(\"Failed to send initd signal: {e}\");\n    }\n\n    let mut msg = unsafe { std::mem::zeroed::<MSG>() };\n    unsafe {\n        loop {\n            let result = GetMessageW(&mut msg, window_handle.hwnd, 0, 0);\n            if result > 0 {\n                TranslateMessage(&msg);\n                DispatchMessageW(&msg);","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/shutdown_hook.rs#L145-L181","documentation":"CreateWindowExW returned a null HWND when creating the hidden 'TAURI_SHUTDOWN_HOOK_WINDOW' window, so the shutdown hook cannot receive its notification message. The last Win32 error is surfaced via Error::from_win32().","triggerScenarios":"Calling setup_shutdown_hook on Windows when window creation fails — invalid parent/style params, desktop or window-station access restrictions, or running in a non-interactive session/service context.","commonSituations":"Running the app as a Windows service or from a session without interactive desktop access, or resource exhaustion preventing window creation.","solutions":["Read the from_win32 error (GetLastError) to pinpoint the cause (e.g. access denied, invalid parameter).","Ensure the process runs in an interactive session; services running as SYSTEM on a non-interactive window station cannot create such windows.","Verify the class was registered successfully in the same hInstance before CreateWindowExW.","Retry creation or degrade to a hook-less shutdown path."],"exampleFix":"// before\nif hidden_window.is_null() {\n    let err = Error::from_win32();\n    anyhow::bail!(\"Failed to create hidden window: {err}\");\n}\n// after\nif hidden_window.is_null() {\n    let err = Error::from_win32();\n    log::warn!(\"hidden shutdown window creation failed ({err}); skipping hook\");\n    return Ok(());\n}","handlingStrategy":"fallback","validationCode":"// non-interactive session heuristic (Windows)\nfn has_interactive_desktop() -> bool {\n    unsafe { !GetConsoleWindow().is_null() || !GetDesktopWindow().is_null() }\n}","typeGuard":null,"tryCatchPattern":"let hook = setup_shutdown_hook().await;\nlet shutdown_hook = match hook {\n    Ok(h) => Some(h),\n    Err(e) => { log::warn!(\"shutdown hook disabled: {e:#}\"); None }\n};","preventionTips":["Run the app in an interactive user session, not as a headless service","Check GetLastError immediately after CreateWindowExW","Make the shutdown hook optional infrastructure with a fallback path"],"tags":["windows","win32","window-creation"],"backgroundTag":"module-init-failed","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}