Preserve Windows sandbox runner launch errors (#49261)

## Why

Restoring the error mode with `SetErrorMode` can overwrite the failure code from `CreateProcessWithLogonW`, causing `RunnerLogonError` to report the wrong error.

## What changed

Capture `GetLastError()` immediately after a failed runner launch, before restoring the previous error mode, and use the saved code for `RunnerLogonError`.

GitOrigin-RevId: c0f4267232306be4d06e7e8accd60f7b77b8d6f3
This commit is contained in:
zm-oai
2026-09-29 13:09:03 +00:00
committed by copyberry
parent af0d68a236
commit f35a0fdc5d
@@ -409,11 +409,12 @@ pub(crate) fn spawn_runner_transport(
&mut pi,
)
};
// Preserve the failure code before SetErrorMode can overwrite it.
let spawn_error = (spawn_res == 0).then(|| unsafe { GetLastError() });
unsafe {
SetErrorMode(previous_error_mode);
}
if spawn_res == 0 {
let err = unsafe { GetLastError() };
if let Some(err) = spawn_error {
return Err(RunnerLogonError { code: err }.into());
}
// Keep the process pinned through the entire startup handshake. Pipes close