Skip to content

Commit c9f3000

Browse files
committed
Convert early exits into errors
1 parent b95f88a commit c9f3000

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

crates/cargo-gpu-cache/src/install_toolchain.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
use anyhow::Context as _;
44
use crossterm::tty::IsTty as _;
55

6-
use crate::user_output;
7-
86
/// Use `rustup` to install the toolchain and components, if not already installed.
97
///
108
/// Pretty much runs:
@@ -108,10 +106,8 @@ fn get_consent_for_toolchain_install(
108106
}
109107

110108
if !std::io::stdout().is_tty() {
111-
user_output!("No TTY detected so can't ask for consent to install Rust toolchain.")?;
112109
log::error!("Attempted to ask for consent when there's no TTY");
113-
#[expect(clippy::exit, reason = "can't ask for user consent if there's no TTY")]
114-
std::process::exit(1);
110+
anyhow::bail!("no TTY detected, so can't ask for consent to install Rust toolchain")
115111
}
116112

117113
log::debug!("asking for consent to install the required toolchain");
@@ -138,8 +134,6 @@ fn get_consent_for_toolchain_install(
138134
{
139135
Ok(())
140136
} else {
141-
crate::user_output!("Exiting...\n")?;
142-
#[expect(clippy::exit, reason = "user requested abort")]
143-
std::process::exit(0);
137+
anyhow::bail!("user denied to install the required toolchain\n");
144138
}
145139
}

crates/cargo-gpu-cache/src/lockfile.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,27 @@ impl LockfileMismatchHandler {
188188
is_force_overwrite_lockfiles_v4_to_v3: bool,
189189
) -> anyhow::Result<()> {
190190
if !is_force_overwrite_lockfiles_v4_to_v3 {
191-
Self::exit_with_v3v4_hack_suggestion();
191+
#[expect(clippy::needless_raw_strings, reason = "false positive")]
192+
const V3V4_HACK_SUGGESTION: &str = r"
193+
Because `cargo gpu` uses a dedicated Rust toolchain for compiling shaders,
194+
it's possible that the `Cargo.lock` manifest version of the shader crate
195+
does not match the `Cargo.lock` manifest version of the workspace.
196+
This is due to a change in the defaults introduced in Rust 1.83.0.
197+
198+
One way to resolve this is to force the workspace to use the same version
199+
of Rust as required by the shader. However, that is not often ideal or even
200+
possible. Another way is to exclude the shader from the workspace. This is
201+
also not ideal if you have many shaders sharing config from the workspace.
202+
203+
Therefore, `cargo gpu build/install` offers a workaround with the argument:
204+
--force-overwrite-lockfiles-v4-to-v3
205+
206+
See `cargo gpu build --help` for more information.
207+
";
208+
#[expect(clippy::non_ascii_literal, reason = "this character is really needed")]
209+
{
210+
anyhow::bail!("conflicting `Cargo.lock` versions detected ⚠️{V3V4_HACK_SUGGESTION}")
211+
}
192212
}
193213

194214
Self::replace_cargo_lock_manifest_version(offending_cargo_lock, "4", "3")
@@ -237,32 +257,6 @@ impl LockfileMismatchHandler {
237257

238258
Ok(())
239259
}
240-
241-
/// Exit and give the user advice on how to deal with the infamous
242-
/// v3/v4 Cargo lockfile version problem.
243-
#[expect(clippy::unwrap_used, reason = "It's CLI output")]
244-
fn exit_with_v3v4_hack_suggestion() {
245-
crate::user_output!(
246-
"Conflicting `Cargo.lock` versions detected ⚠️\n\
247-
Because `cargo gpu` uses a dedicated Rust toolchain for compiling shaders\n\
248-
it's possible that the `Cargo.lock` manifest version of the shader crate\n\
249-
does not match the `Cargo.lock` manifest version of the workspace. This is\n\
250-
due to a change in the defaults introduced in Rust 1.83.0.\n\
251-
\n\
252-
One way to resolve this is to force the workspace to use the same version\n\
253-
of Rust as required by the shader. However that is not often ideal or even\n\
254-
possible. Another way is to exclude the shader from the workspace. This is\n\
255-
also not ideal if you have many shaders sharing config from the workspace.\n\
256-
\n\
257-
Therefore `cargo gpu build/install` offers a workaround with the argument:\n\
258-
--force-overwrite-lockfiles-v4-to-v3\n\
259-
\n\
260-
See `cargo gpu build --help` for more information.\n\
261-
"
262-
)
263-
.unwrap();
264-
std::process::exit(1);
265-
}
266260
}
267261

268262
impl Drop for LockfileMismatchHandler {

crates/cargo-gpu/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() -> ExitCode {
2424
reason = "Our central place for outputting error messages"
2525
)]
2626
{
27-
eprintln!("Error: {error}");
27+
eprintln!("Error: {}", error.root_cause());
2828
return ExitCode::FAILURE;
2929
};
3030
}

0 commit comments

Comments
 (0)