Skip to content

Commit

Permalink
fix(alias): dont panic when resolving an empty alias
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Mar 21, 2024
1 parent 352d8bb commit 46214f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ fn aliased_command(gctx: &GlobalContext, command: &str) -> CargoResult<Option<Ve
let result = user_alias.or_else(|| {
builtin_aliases_execs(command).map(|command_str| vec![command_str.1.to_string()])
});
if result
.as_ref()
.map(|alias| alias.is_empty())
.unwrap_or_default()
{
anyhow::bail!("subcommand is required, but `{alias_name}` is empty");
}
Ok(result)
}

Expand Down
12 changes: 10 additions & 2 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,19 @@ fn empty_alias() {

p.cargo("string")
.with_status(101)
.with_stderr_contains("[..]panicked at[..]")
.with_stderr(
"\
[ERROR] subcommand is required, but `alias.string` is empty
",
)
.run();

p.cargo("array")
.with_status(101)
.with_stderr_contains("[..]panicked at[..]")
.with_stderr(
"\
[ERROR] subcommand is required, but `alias.array` is empty
",
)
.run();
}

0 comments on commit 46214f3

Please sign in to comment.