Skip to content

Commit f8fcb7a

Browse files
authored
Improve error message when showing prompt in non-interactive shell (#235)
# Objective Closes #212. We are showing interactive prompts before we install any required tooling. In non-interactive shells (e.g. CI), this will fail with an error. We should improve this error message to guide the user towards the `--yes` flag, which confirms the prompts automatically. # Solution Use `anyhow`'s `.context(...)` to make the error message more useful, guiding the user towards `--yes`. # Testing Tested in one of [testing repositories in CI](https://github.com/TimJentzsch/bevy_complex_repo/actions/runs/12867761889/job/35873080585?pr=1#step:6:9). New output: ```txt Error: failed to show interactive prompt, try using `--yes` to confirm automatically Caused by: 0: IO error: not a terminal 1: not a terminal Error: Process completed with exit code 1. ```
1 parent 10d0dbc commit f8fcb7a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/external_cli/cargo/install.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
str::FromStr,
44
};
55

6+
use anyhow::Context;
67
use dialoguer::Confirm;
78
use semver::Version;
89

@@ -64,7 +65,10 @@ pub(crate) fn if_needed(
6465
format!("`{program}` is missing, should I install it for you?")
6566
}),
6667
)
67-
.interact()?
68+
.interact()
69+
.context(
70+
"failed to show interactive prompt, try using `--yes` to confirm automatically",
71+
)?
6872
{
6973
exit(1);
7074
}

src/external_cli/rustup.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::{env, ffi::OsString, process::Command};
44

5+
use anyhow::Context;
56
use dialoguer::Confirm;
67

78
/// The rustup command can be customized via the `BEVY_CLI_RUSTUP` env
@@ -33,7 +34,10 @@ pub(crate) fn install_target_if_needed(target: &str, silent: bool) -> anyhow::Re
3334
.with_prompt(format!(
3435
"Compilation target `{target}` is missing, should I install it for you?",
3536
))
36-
.interact()?
37+
.interact()
38+
.context(
39+
"failed to show interactive prompt, try using `--yes` to confirm automatically",
40+
)?
3741
{
3842
anyhow::bail!("User does not want to install target `{target}`.");
3943
}

0 commit comments

Comments
 (0)