Fix int-to-bool truncation in InstallPrerequisites (#40416)

* Fix int-to-bool truncation in InstallPrerequisites InstallPrerequisites() returns bool (reboot required), but on the elevated-install failure path it returned the int exit code directly. This caused implicit int→bool conversion where any nonzero exit code (including errors like exit code 2) was misinterpreted as 'reboot required', leading to incorrect user messaging. Fix: Throw on nonzero exit code instead of returning it, so failures propagate as errors rather than being misinterpreted as reboot signals. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR feedback: use WSL_E_INSTALL_COMPONENT_FAILED with user message The elevated wsl.exe sets its process exit code to -1 on failure, so HRESULT_FROM_WIN32(exitCode) becomes 0xFFFFFFFF and surfaces as an opaque error. Switch to the existing pattern used in WslInstall::InstallOptionalComponents: throw WSL_E_INSTALL_COMPONENT_FAILED with MessageOptionalComponentInstallFailed, which produces a clear `Failed to enable Windows component '<components>' (exit code <code>)` message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed May 5, 2026 at 14:18 UTC d803552b05730d27a28ba745add0145022242a6c
1 file changed +3 -1
src/windows/common/WslClient.cpp
+3 -1
@@ -634,7 +634,9 @@ bool InstallPrerequisites(_In_ bool installWslOptionalComponent)
634 const auto exitCode = LaunchElevated(elevatedCommand.c_str());
635 if (exitCode != 0)
636 {
637 - return exitCode;
637 + THROW_HR_WITH_USER_ERROR(
638 + WSL_E_INSTALL_COMPONENT_FAILED,
639 + Localization::MessageOptionalComponentInstallFailed(wsl::shared::string::Join(missingComponents, L','), exitCode));
640 }
641 }
642 else