diff --git a/src/bin/julialauncher.rs b/src/bin/julialauncher.rs index 6f413812..abaf7ba5 100644 --- a/src/bin/julialauncher.rs +++ b/src/bin/julialauncher.rs @@ -175,26 +175,27 @@ fn get_julia_path_from_channel( juliaupconfig_path: &Path, juliaup_channel_source: JuliaupChannelSource, ) -> Result<(PathBuf, Vec)> { + let channel_valid = is_valid_channel(versions_db, &channel.to_string())?; let channel_info = config_data .installed_channels .get(channel) .ok_or_else(|| match juliaup_channel_source { JuliaupChannelSource::CmdLine => { - if is_valid_channel(versions_db, &channel.to_string()) { + if channel_valid { UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } } else { UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) } } }.into(), JuliaupChannelSource::EnvVar=> { - if is_valid_channel(versions_db, &channel.to_string()) { + if channel_valid { UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } } else { UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) } } }.into(), JuliaupChannelSource::Override=> { - if is_valid_channel(versions_db, &channel.to_string()) { + if channel_valid { UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) } } else { UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) } diff --git a/src/command_default.rs b/src/command_default.rs index 20969be3..bb8e4e8c 100644 --- a/src/command_default.rs +++ b/src/command_default.rs @@ -10,7 +10,7 @@ pub fn run_command_default(channel: &str, paths: &GlobalPaths) -> Result<()> { if !config_file.data.installed_channels.contains_key(channel) { let version_db = load_versions_db(paths) .with_context(|| "`default` command failed to load versions db.")?; - if !is_valid_channel(&version_db, &channel.to_string()) { + if !is_valid_channel(&version_db, &channel.to_string())? { bail!("'{}' is not a valid Julia version.", channel); } else { bail!( diff --git a/src/command_link.rs b/src/command_link.rs index 2bceccbb..a1a4caa4 100644 --- a/src/command_link.rs +++ b/src/command_link.rs @@ -25,7 +25,7 @@ pub fn run_command_link( bail!("Channel name `{}` is already used.", channel) } - if is_valid_channel(&versiondb_data, &channel.to_string()) { + if is_valid_channel(&versiondb_data, &channel.to_string())? { eprintln!("WARNING: The channel name `{}` is also a system channel. By linking your custom binary to this channel you are hiding this system channel.", channel); } diff --git a/src/operations.rs b/src/operations.rs index 21441cf9..7cacd33f 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -434,27 +434,23 @@ pub fn compatible_archs() -> Result> { // which nightly channels are compatible with the current system fn compatible_nightly_channels() -> Result> { - let archs: Result> = compatible_archs(); + let archs: Vec = compatible_archs()?; - if archs.is_ok() { - let channels: Vec = std::iter::once("nightly".to_string()) - .chain(archs?.into_iter().map(|arch| format!("nightly~{}", arch))) - .collect(); - Ok(channels) - } else { - archs - } + let channels: Vec = std::iter::once("nightly".to_string()) + .chain(archs.into_iter().map(|arch| format!("nightly~{}", arch))) + .collect(); + Ok(channels) } // considers the nightly channels as system channels // XXX: does not account for PR channels -pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> bool { +pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> Result { let regular = versions_db.available_channels.contains_key(channel); - let nightly_chans = compatible_nightly_channels(); + let nightly_chans = compatible_nightly_channels()?; - let nightly = nightly_chans.is_ok_and(|nightly_chans| nightly_chans.contains(channel)); - regular || nightly + let nightly = nightly_chans.contains(channel); + Ok(regular || nightly) } // Identify the unversioned name of a nightly (e.g., `latest-macos-x86_64`) for a channel