From aeddc40b9e461bc118382ae62431d39e29f25915 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 15 Apr 2024 11:39:17 +0200 Subject: [PATCH] fix(cli/info): fix crash when checking node version (#9411) closes #9396 --- .changes/tauri-info-no-node.md | 7 +++++++ tooling/cli/src/info/env_nodejs.rs | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 .changes/tauri-info-no-node.md diff --git a/.changes/tauri-info-no-node.md b/.changes/tauri-info-no-node.md new file mode 100644 index 000000000000..5a1b43c25324 --- /dev/null +++ b/.changes/tauri-info-no-node.md @@ -0,0 +1,7 @@ +--- +"tauri-cli": "patch:bug" +"@tauri-apps/cli": "patch:bug" +--- + +Fix `tauri info` crashing when Node.js is not installed. + diff --git a/tooling/cli/src/info/env_nodejs.rs b/tooling/cli/src/info/env_nodejs.rs index a6dfb18dd0f6..9d8583ee2a86 100644 --- a/tooling/cli/src/info/env_nodejs.rs +++ b/tooling/cli/src/info/env_nodejs.rs @@ -40,16 +40,17 @@ pub fn items(metadata: &VersionMetadata) -> Vec { .unwrap_or_default() .trim(); ActionResult::Description(format!("node: {}{}", v, { - let version = semver::Version::parse(v).unwrap(); - let target_version = semver::Version::parse(node_target_ver.as_str()).unwrap(); - if version < target_version { - format!( - " ({}, latest: {})", - "outdated".red(), - target_version.to_string().green() - ) - } else { - "".into() + let version = semver::Version::parse(v); + let target_version = semver::Version::parse(node_target_ver.as_str()); + match (version, target_version) { + (Ok(version), Ok(target_version)) if version < target_version => { + format!( + " ({}, latest: {})", + "outdated".red(), + target_version.to_string().green() + ) + } + _ => "".into(), } })) } else {