Skip to content

Commit 46214f3

Browse files
committed
fix(alias): dont panic when resolving an empty alias
1 parent 352d8bb commit 46214f3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/bin/cargo/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ fn aliased_command(gctx: &GlobalContext, command: &str) -> CargoResult<Option<Ve
148148
let result = user_alias.or_else(|| {
149149
builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
150150
});
151+
if result
152+
.as_ref()
153+
.map(|alias| alias.is_empty())
154+
.unwrap_or_default()
155+
{
156+
anyhow::bail!("subcommand is required, but `{alias_name}` is empty");
157+
}
151158
Ok(result)
152159
}
153160

tests/testsuite/cargo_alias_config.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,19 @@ fn empty_alias() {
447447

448448
p.cargo("string")
449449
.with_status(101)
450-
.with_stderr_contains("[..]panicked at[..]")
450+
.with_stderr(
451+
"\
452+
[ERROR] subcommand is required, but `alias.string` is empty
453+
",
454+
)
451455
.run();
452456

453457
p.cargo("array")
454458
.with_status(101)
455-
.with_stderr_contains("[..]panicked at[..]")
459+
.with_stderr(
460+
"\
461+
[ERROR] subcommand is required, but `alias.array` is empty
462+
",
463+
)
456464
.run();
457465
}

0 commit comments

Comments
 (0)