Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up error messages in the launcher #1070

Merged
merged 13 commits into from
Oct 12, 2024
18 changes: 9 additions & 9 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Context, Result};
use console::Term;
use console::{style, Term};
use is_terminal::IsTerminal;
use itertools::Itertools;
use juliaup::config_file::{load_config_db, JuliaupConfig, JuliaupConfigChannel};
Expand Down Expand Up @@ -140,11 +140,11 @@ fn check_channel_uptodate(
let latest_version = &versions_db
.available_channels
.get(channel)
.ok_or_else(|| {
anyhow!(
.ok_or_else(|| UserError {
msg: format!(
"The channel `{}` does not exist in the versions database.",
channel
)
),
})?
.version;

Expand Down Expand Up @@ -184,24 +184,24 @@ fn get_julia_path_from_channel(
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) }
UserError { msg: format!("Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::EnvVar=> {
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) }
UserError { msg: format!("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 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) }
UserError { msg: format!("Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel)
JuliaupChannelSource::Default => UserError {msg: format!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel) }
})?;

match channel_info {
Expand Down Expand Up @@ -527,7 +527,7 @@ fn main() -> Result<std::process::ExitCode> {

if let Err(err) = &client_status {
if let Some(e) = err.downcast_ref::<UserError>() {
eprintln!("{}", e.msg);
eprintln!("{} {}", style("ERROR:").red().bold(), e.msg);

return Ok(std::process::ExitCode::FAILURE);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/juliaup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() -> Result<()> {
.unwrap();

if !depl_result.IsRegistered().unwrap() {
println!(
eprintln!(
"Failed to register package identity. Error Message ${:?}",
depl_result.ErrorText()
);
Expand Down
4 changes: 2 additions & 2 deletions src/command_selfupdate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
.with_context(|| "Call to Size on update results failed.")?
> 0
{
println!("An update is available.");
eprintln!("An update is available.");

let download_operation = update_manager
.RequestDownloadAndInstallStorePackageUpdatesAsync(&updates)
Expand All @@ -138,7 +138,7 @@ pub fn run_command_selfupdate(paths: &GlobalPaths) -> Result<()> {
})?;
// This code will not be reached if the user opts to install updates
} else {
println!("No updates available.");
eprintln!("No updates available.");
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,24 +405,24 @@ pub fn install_version(
)
})?;

print!("Checking standard library notarization");
eprint!("Checking standard library notarization");
let _ = std::io::stdout().flush();

let exit_status = std::process::Command::new(&julia_path)
.env("JULIA_LOAD_PATH", "@stdlib")
.arg("--startup-file=no")
.arg("-e")
.arg("foreach(p -> begin print('.'); @eval(import $(Symbol(p))) end, filter!(x -> isfile(joinpath(Sys.STDLIB, x, \"src\", \"$(x).jl\")), readdir(Sys.STDLIB)))")
.arg("foreach(p -> begin print(stderr, '.'); @eval(import $(Symbol(p))) end, filter!(x -> isfile(joinpath(Sys.STDLIB, x, \"src\", \"$(x).jl\")), readdir(Sys.STDLIB)))")
// .stdout(std::process::Stdio::null())
// .stderr(std::process::Stdio::null())
// .stdin(std::process::Stdio::null())
.status()
.unwrap();

if exit_status.success() {
println!("done.")
eprintln!("done.")
} else {
println!("failed with {}.", exit_status);
eprintln!("failed with {}.", exit_status);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/channel_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn channel_selection() {
.env("JULIAUP_CHANNEL", "1.7.4")
.assert()
.failure()
.stderr("`1.8.2` is not installed. Please run `juliaup add 1.8.2` to install channel or version.\n");
.stderr("ERROR: `1.8.2` is not installed. Please run `juliaup add 1.8.2` to install channel or version.\n");

// https://github.com/JuliaLang/juliaup/issues/820
Command::cargo_bin("julia")
Expand All @@ -150,5 +150,5 @@ fn channel_selection() {
.env("JULIAUP_CHANNEL", "1.7.4")
.assert()
.failure()
.stderr("`nightly` is not installed. Please run `juliaup add nightly` to install channel or version.\n");
.stderr("ERROR: `nightly` is not installed. Please run `juliaup add nightly` to install channel or version.\n");
}
12 changes: 11 additions & 1 deletion tests/command_initial_setup_from_launcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ fn command_initial_setup() {
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.assert()
.success()
.stdout("");
.stdout(predicate::str::is_empty())
.stderr(
predicate::str::starts_with("Installing Julia 1.11.0").and(
predicate::str::contains("apple.darwin14")
.not()
.or(
predicate::str::contains("Checking standard library notarization")
.and(predicate::str::ends_with("done.\n")),
),
),
);

depot_dir
.child(Path::new("juliaup").join("juliaup.json"))
Expand Down