Skip to content

Commit 7bfe3fb

Browse files
authored
Fix: assume all fields of DistributionInformation are accessible if no context (#6)
1 parent 4384424 commit 7bfe3fb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

wslplugins-rs/src/api/utils.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ pub(crate) fn check_required_version_result(
2222
}
2323

2424
pub(crate) fn check_required_version_result_from_context(
25-
wsl_context: &WSLContext,
25+
wsl_context: Option<&WSLContext>,
2626
required_version: &WSLVersion,
2727
) -> Result<()> {
28-
let current_version = wsl_context.api.version();
29-
check_required_version_result(current_version, required_version)
28+
if let Some(context) = wsl_context {
29+
let current_version = context.api.version();
30+
check_required_version_result(current_version, required_version)
31+
} else {
32+
Ok(())
33+
}
3034
}
3135

3236
#[cfg(test)]

wslplugins-rs/src/distribution_information.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ impl DistributionInformation<'_> {
5555
/// # Returns
5656
/// - `Ok(u32)`: The PID of the init process.
5757
/// # Errors
58-
/// [Error]: If the API version is insufficient.
58+
/// [Error]: If the runtime version version is insufficient if no [WSLContext] found we assume returned value is accessible.
5959
pub fn init_pid(&self) -> Result<u32> {
6060
check_required_version_result_from_context(
61-
WSLContext::get_current_or_panic(),
61+
WSLContext::get_current(),
6262
&WSLVersion::new(2, 0, 5),
6363
)?;
6464
Ok(self.0.InitPid)

0 commit comments

Comments
 (0)