Skip to content

Confusing error when attempting to use alias from --config PATH #15466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ian-h-chamberlain opened this issue Apr 30, 2025 · 2 comments
Closed
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@ian-h-chamberlain
Copy link

ian-h-chamberlain commented Apr 30, 2025

Problem

Hopefully this isn't a duplicate, I haven't been able to find any similar issues so far.

Attempting to use an alias from a config file included with --config fails with an error message that doesn't really explain what went wrong:

$ cat ~/.config/cargo/custom.toml 
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /home/ian/.config/cargo/custom.toml
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [alias]
   2   │ p = "publish --dry-run"
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

$ command cargo --config ~/.config/cargo/custom.toml p 
error: no such command: `p`

    Did you mean `p`?

    View all installed commands with `cargo --list`
    Find a package to install `p` with `cargo search cargo-p` 

The suggested cargo --list is doesn't help, since it still shows the alias from the included config file:

$ command cargo +nightly --config ~/.config/cargo/custom.toml --list | grep -C2 'alias: pub'
    override
    owner                Manage the owners of a crate on the registry
    p                    alias: publish --dry-run
    package              Assemble the local package into a distributable tarball
    pkgid                Print a fully qualified package specification

Steps

  1. Create a config file with an alias (see above for example, e.g. p)
  2. Attempt to use that alias by running cargo --config $PATH p
  3. Observer error

Possible Solution(s)

What I would really like is for this to Just Work (i.e. treat the alias the same as if it was automatically picked up from ~/.config/cargo/config.toml; I wanted to use this as a workaround for #7723 not being implemented so I could add machine-specific aliases by including files from the command line.

At the very least, I think the error message Did you mean `p` message could be updated to include a message about this being unsupported or something like that.

Notes

A workaround is to create e.g. a custom cargo-p subcommand but I'd rather not have to do this for a lot of little convenience aliases and instead keep them all together in one config file.

Version

$ command cargo +nightly -vV
cargo 1.88.0-nightly (7918c7eb5 2025-04-27)
release: 1.88.0-nightly
commit-hash: 7918c7eb59614c39f1c4e27e99d557720976bdd7
commit-date: 2025-04-27
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.4.1)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: NixOS 25.5.0 [64-bit]
@ian-h-chamberlain ian-h-chamberlain added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 30, 2025
@ehuss
Copy link
Contributor

ehuss commented Apr 30, 2025

Thanks for the report! I believe this is a duplicate of #10853, so closing in favor of that.

@ehuss ehuss closed this as completed Apr 30, 2025
@ian-h-chamberlain
Copy link
Author

Ah, I forgot to check if --config alias.foo had the same effect, maybe I would have found that issue if I thought to look for it. Good to know that CARGO_ALIAS_FOO also works, maybe I will be able to use that as a workaround in my case, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants