From 944a6bd395126e7d96ff00a3846e12ea014ba547 Mon Sep 17 00:00:00 2001 From: Robert Vally Date: Fri, 19 May 2017 21:40:58 +0800 Subject: [PATCH 1/2] Supress confusing NotADirectory error and show only override toolchain not installed. --- src/rustup/config.rs | 15 +++++++++++++-- src/rustup/errors.rs | 4 ++++ tests/cli-rustup.rs | 13 +++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/rustup/config.rs b/src/rustup/config.rs index 1ccca4fa03..9c7732edf7 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use errors::*; use notifications::*; use rustup_dist::{temp, dist}; -use rustup_utils::utils; +use rustup_utils::{self, utils}; use toolchain::{Toolchain, UpdateStatus}; use telemetry_analysis::*; use settings::{TelemetryMode, SettingsFile, DEFAULT_METADATA_VERSION}; @@ -233,7 +233,18 @@ impl Cfg { Ok(s.find_override(path, self.notify_handler.as_ref())) })); if let Some((name, reason_path)) = result { - let toolchain = try!(self.verify_toolchain(&name).chain_err(|| ErrorKind::ToolchainNotInstalled(name.to_string()))); + let toolchain = match self.verify_toolchain(&name) { + Ok(t) => { t }, + Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::NotADirectory { .. }), _)) => { + // Strip the confusing NotADirectory error and only mention that the override + // toolchain is not installed. + return Err(ErrorKind::OverrideToolchainNotInstalled(name.to_string()).into()) + }, + Err(e) => return Err(e).chain_err(|| { + ErrorKind::OverrideToolchainNotInstalled(name.to_string()) + }) + + }; return Ok(Some((toolchain, OverrideReason::OverrideDB(reason_path)))); } diff --git a/src/rustup/errors.rs b/src/rustup/errors.rs index 6970676ef1..1a60b6bd42 100644 --- a/src/rustup/errors.rs +++ b/src/rustup/errors.rs @@ -22,6 +22,10 @@ error_chain! { description("toolchain is not installed") display("toolchain '{}' is not installed", t) } + OverrideToolchainNotInstalled(t: String) { + description("override toolchain is not installed") + display("override toolchain '{}' is not installed", t) + } BinaryNotFound(t: String, bin: String) { description("toolchain does not contain binary") display("toolchain '{}' does not have the binary `{}`", t, bin) diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 05f2e5690f..6d1c6a5f70 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -512,8 +512,17 @@ fn show_toolchain_override_not_installed() { expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]); // I'm not sure this should really be erroring when the toolchain // is not installed; just capturing the behavior. - expect_err(config, &["rustup", "show"], - for_host!(r"error: toolchain 'nightly-{0}' is not installed")); + let path = format!("toolchains/nightly-{0}", &this_host_triple()); + let path = config.rustupdir.join(path); + + let mut cmd = clitools::cmd(config, "rustup", &["show"]); + clitools::env(config, &mut cmd); + let out = cmd.output().unwrap(); + assert!(!out.status.success()); + let stderr = String::from_utf8(out.stderr).unwrap(); + assert!(stderr.starts_with( + for_host!("error: override toolchain 'nightly-{0}' is not installed"))); + assert!(!stderr.contains("info: caused by: not a directory: ")); }); } From 1f27bbf269ed2a0e557a4de336da988dbb9afa7c Mon Sep 17 00:00:00 2001 From: Robert Vally Date: Sat, 20 May 2017 11:11:14 +0800 Subject: [PATCH 2/2] 820 - Removing some dead code. --- src/rustup/config.rs | 2 +- tests/cli-rustup.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/rustup/config.rs b/src/rustup/config.rs index 9c7732edf7..87b1b3ccdf 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use errors::*; use notifications::*; use rustup_dist::{temp, dist}; -use rustup_utils::{self, utils}; +use rustup_utils::utils; use toolchain::{Toolchain, UpdateStatus}; use telemetry_analysis::*; use settings::{TelemetryMode, SettingsFile, DEFAULT_METADATA_VERSION}; diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 6d1c6a5f70..a4f5f7bd7b 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -512,9 +512,6 @@ fn show_toolchain_override_not_installed() { expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]); // I'm not sure this should really be erroring when the toolchain // is not installed; just capturing the behavior. - let path = format!("toolchains/nightly-{0}", &this_host_triple()); - let path = config.rustupdir.join(path); - let mut cmd = clitools::cmd(config, "rustup", &["show"]); clitools::env(config, &mut cmd); let out = cmd.output().unwrap();