From b14faa41413e523e242c78491fccea7b65fbf2ad Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sun, 30 Dec 2018 15:43:21 +0900 Subject: [PATCH 1/2] Add more detail error messages when installing with some components has failed --- src/rustup-dist/src/errors.rs | 18 ++++++++++++++++-- tests/cli-misc.rs | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/rustup-dist/src/errors.rs b/src/rustup-dist/src/errors.rs index 3d3187c723..cd4af12691 100644 --- a/src/rustup-dist/src/errors.rs +++ b/src/rustup-dist/src/errors.rs @@ -5,6 +5,10 @@ use std::io::{self, Write}; use std::path::PathBuf; use toml; +pub const TOOLSTATE_MSG: &str = "if you require these components, please install and use the latest successful build version, \ + which you can find at https://rust-lang-nursery.github.io/rust-toolstate, for example.\n\ + rustup install nightly-2018-12-27"; + error_chain! { links { Utils(rustup_utils::Error, rustup_utils::ErrorKind); @@ -127,11 +131,21 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest) -> String { if same_target { let mut cs_strs = cs.iter().map(|c| format!("'{}'", c.short_name(manifest))); let cs_str = cs_strs.join(", "); - let _ = write!(buf, "some components unavailable for download: {}", cs_str); + let _ = write!( + buf, + "some components unavailable for download: {}\n{}", + cs_str, + TOOLSTATE_MSG, + ); } else { let mut cs_strs = cs.iter().map(|c| c.description(manifest)); let cs_str = cs_strs.join(", "); - let _ = write!(buf, "some components unavailable for download: {}", cs_str); + let _ = write!( + buf, + "some components unavailable for download: {}\n{}", + cs_str, + TOOLSTATE_MSG, + ); } } diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 08aa775bf1..d5350cece6 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -12,6 +12,7 @@ use rustup_mock::clitools::{ expect_timeout_ok, run, set_current_dist_date, this_host_triple, Config, Scenario, }; use rustup_utils::{raw, utils}; +use rustup_dist::errors::{TOOLSTATE_MSG}; use std::env::consts::EXE_SUFFIX; use std::ops::Add; @@ -808,7 +809,10 @@ fn update_unavailable_rustc() { expect_err( config, &["rustup", "update", "nightly"], - "some components unavailable for download: 'rustc', 'cargo'", + format!( + "some components unavailable for download: 'rustc', 'cargo'\n{}", + TOOLSTATE_MSG + ).as_str(), ); expect_stdout_ok(config, &["rustc", "--version"], "hash-n-1"); From cec8cbb0b902895d07d9c71d6c8cb40b0826b460 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Mon, 7 Jan 2019 18:45:51 +0900 Subject: [PATCH 2/2] cargo fmt --- src/rustup-dist/src/errors.rs | 25 ++++++++++++------------- tests/cli-misc.rs | 5 +++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/rustup-dist/src/errors.rs b/src/rustup-dist/src/errors.rs index cd4af12691..e513c10fb5 100644 --- a/src/rustup-dist/src/errors.rs +++ b/src/rustup-dist/src/errors.rs @@ -5,9 +5,10 @@ use std::io::{self, Write}; use std::path::PathBuf; use toml; -pub const TOOLSTATE_MSG: &str = "if you require these components, please install and use the latest successful build version, \ - which you can find at https://rust-lang-nursery.github.io/rust-toolstate, for example.\n\ - rustup install nightly-2018-12-27"; +pub const TOOLSTATE_MSG: &str = + "if you require these components, please install and use the latest successful build version, \ + which you can find at https://rust-lang-nursery.github.io/rust-toolstate, for example.\n\ + rustup install nightly-2018-12-27"; error_chain! { links { @@ -132,20 +133,18 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest) -> String { let mut cs_strs = cs.iter().map(|c| format!("'{}'", c.short_name(manifest))); let cs_str = cs_strs.join(", "); let _ = write!( - buf, - "some components unavailable for download: {}\n{}", - cs_str, - TOOLSTATE_MSG, - ); + buf, + "some components unavailable for download: {}\n{}", + cs_str, TOOLSTATE_MSG, + ); } else { let mut cs_strs = cs.iter().map(|c| c.description(manifest)); let cs_str = cs_strs.join(", "); let _ = write!( - buf, - "some components unavailable for download: {}\n{}", - cs_str, - TOOLSTATE_MSG, - ); + buf, + "some components unavailable for download: {}\n{}", + cs_str, TOOLSTATE_MSG, + ); } } diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index d5350cece6..c227149ec7 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -7,12 +7,12 @@ extern crate rustup_utils; extern crate tempdir; extern crate time; +use rustup_dist::errors::TOOLSTATE_MSG; use rustup_mock::clitools::{ self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, expect_stdout_ok, expect_timeout_ok, run, set_current_dist_date, this_host_triple, Config, Scenario, }; use rustup_utils::{raw, utils}; -use rustup_dist::errors::{TOOLSTATE_MSG}; use std::env::consts::EXE_SUFFIX; use std::ops::Add; @@ -812,7 +812,8 @@ fn update_unavailable_rustc() { format!( "some components unavailable for download: 'rustc', 'cargo'\n{}", TOOLSTATE_MSG - ).as_str(), + ) + .as_str(), ); expect_stdout_ok(config, &["rustc", "--version"], "hash-n-1");