Skip to content

Commit

Permalink
Add better help texts for Error::ShellProgramNotFound
Browse files Browse the repository at this point in the history
add bun, deno, elixir and split the matching logic into different OS
  • Loading branch information
enkerewpo committed Dec 13, 2024
1 parent 475debf commit e8362ac
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions compiler-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,20 +1032,56 @@ https://gleam.run/getting-started/installing/",
Documentation for installing rebar3 can be viewed here:
https://gleam.run/getting-started/installing/",
),
_ => (),
}
match (program.as_str(), env::consts::OS) {
// TODO: Further suggestions for other OSes?
("erl" | "erlc" | "escript", "macos") => text.push_str(
"
You can also install Erlang via homebrew using \"brew install erlang\"",
),
("rebar3", "macos") => text.push_str(
"bun" => text.push_str(
"
You can also install rebar3 via homebrew using \"brew install rebar3\"",
Documentation for installing bun can be viewed here:
https://bun.sh/docs/installation/
You may need to restart your shell after installing bun.",
),
_ => (),
};
}
match env::consts::OS {
"macos" => {
fn brew_install(program: &str) -> String {
format!("\nYou can install {} via homebrew: brew install {}", program, program)
}
match program.as_str() {
"erl" | "erlc" | "escript" => text.push_str(&brew_install("erlang")),
"rebar3" => text.push_str(&brew_install("rebar3")),
"deno" => text.push_str(&brew_install("deno")),
"elixir" => text.push_str(&brew_install("elixir")),
other => text.push_str(&wrap_format!("
You might need to install {other} manually on your macOS."
)),
}
}
"linux" => {
if let Ok(distro) = std::fs::read_to_string("/etc/os-release") {
if distro.contains("ubuntu") || distro.contains("debian") {
text.push_str(&wrap_format!("
You can try installing {program} using apt: \"sudo apt install {program}\".
If that doesn't work, you might need to install {program} manually."
));
} else if distro.contains("fedora") || distro.contains("centos") {
text.push_str(&wrap_format!("
You can try installing {program} using dnf: \"sudo dnf install {program}\".
If that doesn't work, you might need to install {program} manually."
));
} else {
text.push_str(&wrap_format!("
You might need to install {program} manually."
));
}
} else {
text.push_str(&wrap_format!("
Failed to determine your Linux distribution, please install {program} manually."
));
}
}
_ => text.push_str(&format!("
You might need to install {program} manually."
)),
}

vec![Diagnostic {
title: "Program not found".into(),
Expand Down

0 comments on commit e8362ac

Please sign in to comment.