Skip to content

Commit

Permalink
feat: better error message when installing Elixir without Erlang
Browse files Browse the repository at this point in the history
Also adds test installing elixir without erlang
  • Loading branch information
tsloughter committed Aug 31, 2024
1 parent 3772721 commit a7f0595
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 6 additions & 1 deletion shelltests/installs.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ target/debug/beamup install gleam v1.4.1

# force an install of the same version
target/debug/beamup install -f true gleam v1.4.1
>>>=0
>>>=0

# test attempt to install elixir without erlang
target/debug/beamup install elixir latest
>>>2 /Error: No default Erlang installation found. Install an Erlang version, like `beamup install erlang latest` or set a default with `beamup default erlang <ID>` first./
>>>=1
4 changes: 2 additions & 2 deletions src/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub fn run(
_repo: &Option<String>,
force: &Option<bool>,
) -> Result<String, Report> {
let release_dir = config::language_release_dir(language, id, force)?;

let out_dir = TempDir::new(github_repo.repo.as_str())?;
let file = download_asset(language, out_dir.path(), github_repo, release)?;
debug!("file {:?} downloaded", file);
Expand All @@ -32,6 +30,8 @@ pub fn run(
)
})?;

let release_dir = config::language_release_dir(language, id, force)?;

// TODO: better ways to check the type than the extension
let ext = file.extension().map_or("", |e| e.to_str().unwrap_or(""));
match ext {
Expand Down
9 changes: 6 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ fn get_language_config(language: &languages::Language, config: &Config) -> Langu

fn get_default_id(lc: &Option<LanguageConfig>) -> Result<String> {
match lc {
None => Err(eyre!("No default found for {:?}", lc)),
None => Err(eyre!("No default found for language {:?}", lc)),
Some(lc) => match &lc.default {
None => Err(eyre!("No default found for language")),
None => Err(eyre!("No default found for language {:?}", lc)),
Some(default) => {
debug!("Found default {:?}", default);
Ok(default.to_string())
Expand Down Expand Up @@ -89,7 +89,10 @@ fn get_local_id(language_str: String, local_config: &Option<toml::Table>) -> Opt
}

pub fn get_otp_major_vsn() -> Result<String> {
let dir = install_to_use("erl")?;
let dir = match install_to_use("erl") {
Ok(dir) => Ok(dir),
Err(_) => Err(eyre!("No default Erlang installation found. Install an Erlang version, like `beamup install erlang latest` or set a default with `beamup default erlang <ID>` first.")),
}?;
let releases_dir = Path::new(&dir).join("lib").join("erlang").join("releases");
let mut otps = std::fs::read_dir(&releases_dir)?;
let binding = otps
Expand Down
4 changes: 2 additions & 2 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pub fn download_asset(
GithubRepo { org, repo }: &GithubRepo,
tag: &str,
) -> Result<PathBuf, Report> {
let asset_name = asset_name(language, tag)?;

let rt = setup_tokio();

let release_result = if tag == "latest" {
Expand Down Expand Up @@ -186,8 +188,6 @@ pub fn download_asset(
}
};

let asset_name = asset_name(language, tag)?;

match assets.iter().find(|&asset| *asset.name == asset_name) {
Some(asset) => {
let file = out_dir.join(asset_name);
Expand Down

0 comments on commit a7f0595

Please sign in to comment.