From 5131b843ae230d7a5a4120aa5f0eb150e0779350 Mon Sep 17 00:00:00 2001 From: ityuany <519495771@qq.com> Date: Tue, 23 Jul 2024 20:50:27 +0800 Subject: [PATCH] modify UnsupportedNodeVersionError --- crates/snm_shim/src/get_node_bin_dir.rs | 3 ++- crates/snm_utils/src/snm_error.rs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/snm_shim/src/get_node_bin_dir.rs b/crates/snm_shim/src/get_node_bin_dir.rs index 2e16c643..b97e2350 100644 --- a/crates/snm_shim/src/get_node_bin_dir.rs +++ b/crates/snm_shim/src/get_node_bin_dir.rs @@ -26,7 +26,8 @@ pub async fn get_node_bin_dir() -> Result { if node_white_list.contains(&version).not() { return Err(SnmError::UnsupportedNodeVersionError { - version: version.to_string(), + actual: version.to_string(), + expect: node_white_list, }); } diff --git a/crates/snm_utils/src/snm_error.rs b/crates/snm_utils/src/snm_error.rs index 5496714a..1be9bf03 100644 --- a/crates/snm_utils/src/snm_error.rs +++ b/crates/snm_utils/src/snm_error.rs @@ -81,8 +81,8 @@ pub enum SnmError { actual: String, }, - #[error("Unsupported node v{version} ")] - UnsupportedNodeVersionError { version: String }, + #[error("Unsupported node {actual} ")] + UnsupportedNodeVersionError { actual: String, expect: Vec }, } pub fn friendly_error_message(error: SnmError) { @@ -275,6 +275,19 @@ pub fn friendly_error_message(error: SnmError) { actual.red(), ); } + SnmError::UnsupportedNodeVersionError { actual, expect } => { + eprintln!( + r##"👹 Unsupported node {} , Only the following list is supported: + +{}"##, + actual.bold().red(), + expect + .iter() + .map(|item| format!("- {}", item).to_string()) + .collect::>() + .join("\r\n") + ); + } SnmError::HttpStatusCodeUnOk | SnmError::NotFoundPackageJsonError(_) | SnmError::GetWorkspaceError @@ -282,7 +295,6 @@ pub fn friendly_error_message(error: SnmError) { | SnmError::NetworkError(_) | SnmError::DialoguerError(_) | SnmError::VarError(_) - | SnmError::UnsupportedNodeVersionError { version: _ } | SnmError::CannotFindDefaultCommand { command: _ } | SnmError::ZipError(_) | SnmError::IOError(_) => {