From 053e5ca41c24407096b7e668c906ff2fb90e6deb Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 30 Sep 2023 17:17:27 +0800 Subject: [PATCH] Don't panic when python interpreter cannot be executed on Windows --- src/python_interpreter/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/python_interpreter/mod.rs b/src/python_interpreter/mod.rs index 2d632bce7..49a7c66a5 100644 --- a/src/python_interpreter/mod.rs +++ b/src/python_interpreter/mod.rs @@ -150,15 +150,20 @@ fn find_all_windows( } let executable = capture.get(6).unwrap().as_str(); - let version = format!("-{major}.{minor}-{pointer_width}"); - let output = Command::new(executable) - .args(["-c", code]) - .output() - .unwrap(); + let output = Command::new(executable).args(["-c", code]).output(); + let output = match output { + Ok(output) => output, + Err(err) => { + eprintln!( + "⚠️ Warning: failed to determine the path to python for `{executable}`: {err}" + ); + continue; + } + }; let path = str::from_utf8(&output.stdout).unwrap().trim(); if !output.status.success() || path.trim().is_empty() { eprintln!( - "⚠️ Warning: couldn't determine the path to python for `py {version}`" + "⚠️ Warning: couldn't determine the path to python for `{executable}`" ); continue; }