Skip to content

Commit 62f32f7

Browse files
committed
Made some errors non-fatal.
1 parent 703b405 commit 62f32f7

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/cli/common.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,17 @@ pub fn report_error(e: &Error) {
522522
}
523523
}
524524
}
525+
526+
pub fn ignorable_error(error: crate::errors::Error, no_prompt: bool) -> Result<()> {
527+
report_error(&error);
528+
if no_prompt {
529+
warn!("continuing (because the -y flag is set and the error is ignorable)");
530+
Ok(())
531+
} else {
532+
if confirm("\nContinue? (y/N)", false).unwrap_or(false) {
533+
Ok(())
534+
} else {
535+
Err(error)
536+
}
537+
}
538+
}

src/cli/self_update.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! Deleting the running binary during uninstall is tricky
3131
//! and racy on Windows.
3232
33-
use crate::common::{self, Confirm};
33+
use crate::common::{self, ignorable_error, Confirm};
3434
use crate::errors::*;
3535
use crate::markdown::md;
3636
use crate::term2;
@@ -235,7 +235,7 @@ fn canonical_cargo_home() -> Result<String> {
235235
/// `CARGO_HOME`/bin, hard-linking the various Rust tools to it,
236236
/// and adding `CARGO_HOME`/bin to PATH.
237237
pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpts) -> Result<()> {
238-
do_pre_install_sanity_checks()?;
238+
do_pre_install_sanity_checks(no_prompt)?;
239239
do_pre_install_options_sanity_checks(&opts)?;
240240
check_existence_of_rustc_or_cargo_in_path(no_prompt)?;
241241
#[cfg(unix)]
@@ -378,8 +378,8 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool) -> Result<()> {
378378
// Only the test runner should set this
379379
let skip_check = env::var_os("RUSTUP_INIT_SKIP_PATH_CHECK");
380380

381-
// Ignore this check if called with no prompt (-y) or if the environment variable is set
382-
if no_prompt || skip_check == Some("yes".into()) {
381+
// Skip this if the environment variable is set
382+
if skip_check == Some("yes".into()) {
383383
return Ok(());
384384
}
385385

@@ -390,13 +390,12 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool) -> Result<()> {
390390
err!("Otherwise you may have confusion unless you are careful with your PATH");
391391
err!("If you are sure that you want both rustup and your already installed Rust");
392392
err!("then please restart the installation and pass `-y' to bypass this check.");
393-
Err("cannot install while Rust is installed".into())
394-
} else {
395-
Ok(())
393+
ignorable_error("cannot install while Rust is installed".into(), no_prompt)?;
396394
}
395+
Ok(())
397396
}
398397

399-
fn do_pre_install_sanity_checks() -> Result<()> {
398+
fn do_pre_install_sanity_checks(no_prompt: bool) -> Result<()> {
400399
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
401400
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
402401
let rustup_sh_path = utils::home_dir().unwrap().join(".rustup");
@@ -412,7 +411,7 @@ fn do_pre_install_sanity_checks() -> Result<()> {
412411
"run `{}` as root to uninstall Rust",
413412
uninstaller_path.display()
414413
);
415-
// return Err("cannot install while Rust is installed".into());
414+
ignorable_error("cannot install while Rust is installed".into(), no_prompt)?;
416415
}
417416

418417
if rustup_sh_exists {
@@ -422,7 +421,10 @@ fn do_pre_install_sanity_checks() -> Result<()> {
422421
warn!("or, if you already have rustup installed, you can run");
423422
warn!("`rustup self update` and `rustup toolchain list` to upgrade");
424423
warn!("your directory structure");
425-
return Err("cannot install while rustup.sh is installed".into());
424+
ignorable_error(
425+
"cannot install while rustup.sh is installed".into(),
426+
no_prompt,
427+
)?;
426428
}
427429

428430
Ok(())

0 commit comments

Comments
 (0)