Add context to Windows sandbox runtime registration errors (#48531)

Identify the failing setup step when starting, completing, or verifying managed runtime package registration, granting metadata permissions, or persisting the completed registration. Preserve the underlying errors with `anyhow::Context`.

GitOrigin-RevId: 85f712faf2519e95704d7e8cea15d2deeed0d51e
This commit is contained in:
zm-oai
2026-09-26 20:26:34 +00:00
committed by copyberry
parent 7f6c0f9387
commit 06f97622f8
@@ -163,7 +163,8 @@ pub(crate) fn provision(
None,
DeploymentOptions::None,
)?)
})?;
})
.context("start managed runtime package registration")?;
// As with provisioning, retain the request's resources until Windows finishes.
// A client timeout or an unreadable status cannot safely release the profile.
let mut status_error_logged = false;
@@ -193,18 +194,26 @@ pub(crate) fn provision(
}
std::thread::sleep(Duration::from_millis(50));
}
operation.GetResults()?.ExtendedErrorCode()?.ok()?;
operation
.GetResults()
.and_then(|result| result.ExtendedErrorCode())
.and_then(windows::core::HRESULT::ok)
.context("finish managed runtime package registration")?;
ensure!(
registered_packages(&profile.user_sid, &family)?.contains(full_name),
registered_packages(&profile.user_sid, &family)
.context("verify managed runtime package registration")?
.contains(full_name),
"runtime registration completed without the expected package"
);
}
metadata::grant(identity.token.0, &profile.user_sid, record)?;
metadata::grant(identity.token.0, &profile.user_sid, record)
.context("grant managed runtime metadata permissions")?;
profile.unload_profile()?;
}
if !receipt_current {
record.runtime_mut()?.ready_package = Some(full_name.to_string());
crate::installation_record::save_runtime(record)?;
crate::installation_record::save_runtime(record)
.context("persist completed managed runtime registration")?;
}
Ok(())
}