{"record":{"id":"2a57c9dbb5dfd769","repo":"BigPizzaV3/CodexPlusPlus","slug":"shellexecutew-returned-code","errorCode":null,"errorMessage":"ShellExecuteW returned {code}","messagePattern":"ShellExecuteW returned (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/windows_integration.rs","lineNumber":173,"sourceCode":"}\n\n#[cfg(windows)]\npub fn open_url(url: &str) -> anyhow::Result<()> {\n    let operation = wide_null(\"open\");\n    let file = wide_null(url);\n    let result = unsafe {\n        ShellExecuteW(\n            None,\n            PCWSTR(operation.as_ptr()),\n            PCWSTR(file.as_ptr()),\n            PCWSTR::null(),\n            PCWSTR::null(),\n            SW_SHOWMINNOACTIVE,\n        )\n    };\n    let code = result.0 as isize;\n    if code <= 32 {\n        anyhow::bail!(\"ShellExecuteW returned {code}\");\n    }\n    Ok(())\n}\n\n#[cfg(windows)]\npub fn set_current_user_string_value(subkey: &str, name: &str, value: &str) -> anyhow::Result<()> {\n    with_created_current_user_key(subkey, |key| {\n        let value = wide_null(value);\n        let bytes = slice_as_u8(&value);\n        unsafe {\n            RegSetValueExW(\n                key,\n                PCWSTR(wide_null(name).as_ptr()),\n                0,\n                REG_SZ,\n                Some(bytes),\n            )\n        }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/windows_integration.rs#L155-L191","documentation":"open_url uses the Win32 ShellExecuteW API to open a URL/document; Windows reports success only when the return code is greater than 32. Any return value <= 32 (e.g. SE_ERR_NOASSOC, SE_ERR_ACCESSDENIED) is converted into this error showing the raw code.","triggerScenarios":"Calling open_url when the OS cannot open the target: no application associated with the URL/scheme, access denied, file not found, or out-of-resources errors returned by ShellExecuteW.","commonSituations":"Opening a custom URL scheme nobody handles; default-browser association broken on the machine; running in a restricted/service session where shell execution is denied; target file deleted between check and open.","solutions":["Check the returned code: for 'no association' register or choose a handler (e.g. open with explicit 'cmd /c start' or a browser executable path)","Ensure the process runs in an interactive user session with permission to launch shell items","Validate the URL/file exists and uses a well-known scheme (http/https) before calling open_url; fall back to printing the URL for manual opening"],"exampleFix":"// before\nopen_url(\"myapp://deep-link\")?;\n// after\nmatch open_url(\"myapp://deep-link\") {\n    Ok(()) => {},\n    Err(e) => {\n        eprintln!(\"could not open automatically ({}); visit manually\", e);\n    }\n}","handlingStrategy":"try-catch","validationCode":"fn openable_target(url: &str) -> bool {\n    url::Url::parse(url).map(|u| matches!(u.scheme(), \"http\" | \"https\")).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match open_url(url) {\n    Err(e) => {\n        // Surface the ShellExecuteW code and fall back to clipboard/print\n        eprintln!(\"open failed: {e}; URL copied for manual open\");\n    }\n    Ok(()) => {}\n}","preventionTips":["Only open http/https URLs or files with known associations","Keep default-browser associations healthy on target machines","Run in an interactive session with shell-launch permissions"],"tags":["windows","win32","shell"],"backgroundTag":"http-error-response","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}