Skip to content

Commit

Permalink
modify UnsupportedNodeVersionError
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jul 23, 2024
1 parent eea1c28 commit 5131b84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/snm_shim/src/get_node_bin_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub async fn get_node_bin_dir() -> Result<String, SnmError> {

if node_white_list.contains(&version).not() {
return Err(SnmError::UnsupportedNodeVersionError {
version: version.to_string(),
actual: version.to_string(),
expect: node_white_list,
});
}

Expand Down
18 changes: 15 additions & 3 deletions crates/snm_utils/src/snm_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> },
}

pub fn friendly_error_message(error: SnmError) {
Expand Down Expand Up @@ -275,14 +275,26 @@ 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::<Vec<String>>()
.join("\r\n")
);
}
SnmError::HttpStatusCodeUnOk
| SnmError::NotFoundPackageJsonError(_)
| SnmError::GetWorkspaceError
| SnmError::DeserializeError(_)
| SnmError::NetworkError(_)
| SnmError::DialoguerError(_)
| SnmError::VarError(_)
| SnmError::UnsupportedNodeVersionError { version: _ }
| SnmError::CannotFindDefaultCommand { command: _ }
| SnmError::ZipError(_)
| SnmError::IOError(_) => {
Expand Down

0 comments on commit 5131b84

Please sign in to comment.