Asdf: There is no way to silence spurious "No version set for command" warnings.

Created on 17 Dec 2020  路  8Comments  路  Source: asdf-vm/asdf

Describe the bug

I do not want asdf to spam my shell with warnings about no version being set for a particular command. For example, I have ruby 2.7.2 installed. When I switch into a directory with that plugin and version set, asdf correctly switches to use the correct version. Nice.

However when I'm outside of a directory without that plugin version set, for example my ~ home directory, I get this junk:

No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 2.7.2
$ 

Yes. I know I don't have a version set. That's intended. I want to fallback to using the system installed ruby. I don't want to put a .ruby-version file in my home directory, thank you very much.

To Reproduce

Steps to reproduce the behavior:

  1. Install asdf and the ruby plugin.

    brew install asdf
    asdf plugin-add ruby https://github.com/asdf-vm/asdf-ruby.git
    asdf install ruby 2.7.2
    echo "legacy_version_file = yes" > ~/.asdfrc
    
  2. Add the following to your ~/.profile file in the correct place:

    ASDF_PREFIX="$(brew --prefix asdf 2>/dev/null || true)"
    if [[ -d "$ASDF_PREFIX" ]]; then
        # shellcheck disable=SC1090
        source "$ASDF_PREFIX/asdf.sh"
    fi
    
  3. Open a new shell. Before the first prompt you will see the spurious junk.

  4. Hit enter a few times. You'll get this junk before every single prompt. 馃槰

Expected behavior

There should be a way to disable this. I tried:

source "$ASDF_PREFIX/asdf.sh" &> /dev/null

But to no avail.

Actual behavior

I get a spurious warning before my shell terminal prompt. For every single prompt. Watch what happens if I just hit enter a few times:

No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 2.7.2
$
No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 2.7.2
$
No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 2.7.2
$
No version set for command ruby
Consider adding one of the following versions in your config file at
ruby 2.7.2
$

What the heck?

Environment

OS:
Darwin work 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin

SHELL:
zsh 5.8 (x86_64-apple-darwin19.6.0)

ASDF VERSION:
v0.8.0

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/usr/local/opt/asdf

ASDF INSTALLED PLUGINS:
ruby                         https://github.com/asdf-vm/asdf-ruby.git

asdf plugins affected (if relevant):

  • ruby

At least that's the only plugin I've checked. But I think this is generic behavior for all plugins? Maybe?

bug

All 8 comments

It looks like these lines are the culprit: https://github.com/asdf-vm/asdf/blob/ac1a35b85bde049b9e2d531032eb55534e38ffe7/lib/utils.bash#L782

I need to disable those printf calls. I honestly don't see why they exist in the first place.

Wait. What the heck. I commented out those printf calls but it seems that this line https://github.com/asdf-vm/asdf/blob/ac1a35b85bde049b9e2d531032eb55534e38ffe7/lib/utils.bash#L785 also prints out some junk. For me it's printing out ruby 2.7.2. And when I comment it out, asdf seems to break. Now when I start a new shell:

$ ruby
# exit code 126, command not found

$ command -v ruby
/Users/me/.asdf/shims/ruby

馃槵

I finally worked around this by adding

ruby system

to the file ~/.tool-versions. It's most disconcerting that I have to create a file in my home directory to resolve this issue.

Thanks for reporting @lexicalunit I'm sorry about this poor experience. I am able to reproduce (with nodejs plugin) this behaviour as well (excpet for "spurious warning on before my shell terminal prompt. For every single prompt", for me it is only on shell login which may be because I am using .zshrc and not .profile, I am not too sure of this part)

As for the issue happening at all, it arises from no config file at all and is resolved by creating the $HOME/.tool-versions which is where asdf looks for global default values (this file can be configured which you will see https://asdf-vm.com/#/core-configuration)

It's most disconcerting that I have to create a file in my home directory to resolve this issue.

This requirement should be _no more_ disconcerting than our requirement of the $HOME/.asdfrc. It is confusing however for users who have set legacy_version_file, I suspect this is either poor communication about a requirement OR an edge case.

This is an unhelpful error message because it usually lists the last config file it looked for a version in, but because no file is found it just says:

Consider adding one of the following versions in your config file at

instead of

Consider adding one of the following versions in your config file at /home/jthegedus/.tool-versions


These are the changes we will need to resolve this issue:

  1. clarify if legacy_version_file = yes should remove the need of a $HOME/.tool-versions
  2. clarify if $HOME/.tool-versions is a required part of the setup (I have always thought that it was but may be mistaken)
  3. when no config file exists up the entire filesystem tree, report a different error than if a config file is found but with no entry for the particular plugin

Wait. I was just working in another project and I used yarn and this happened:

$ yarn add discord-oauth2
No version set for command yarn
Consider adding one of the following versions in your config file at /Users/me/.tool-versions
yarn 1.22.5

What? Simply because I installed asdf I now am no longer able to even just use yarn without getting spammed? What in the heck is this? I've heard of opinionated software before but this is downright viral malware. How do I turn this off? I don't want to use asdf with yarn. I'm perfectly happy with my own installation of yarn.

asdf is only aware of commands and tries to control their versioning if there is a shim for that command. So if you have installed a plugin that creates a shim for yarn, then this is expected behaviour. If you have not installed a plugin that manages yarn then this is an issue with your setup as asdf should not be doing this without your specifically allowing it so. We have gone to great lengths to not automate setup of the tool to allow different users with different needs to manage their own configuration, this comes with more steps during setup.

You can view the shims asdf has created in ~/.asdf/shims which I expect to only have Ruby commands shimmed by the ruby plugin you installed to be here.

Being the first user to experience this particular issue, it leads me to think there is an issue with your configuration.

From what I gather from the initial information you shared, the only difference I can see is your use of ~/.profile instead of ~/.zshrc. I would suggest moving

ASDF_PREFIX="$(brew --prefix asdf 2>/dev/null || true)"
if [[ -d "$ASDF_PREFIX" ]]; then
    # shellcheck disable=SC1090
    source "$ASDF_PREFIX/asdf.sh"
fi

from ~/.profile to your ~/.zshrc, closing all shells, logging out of your user on your machine and then trying again.

I am unfamiliar with edge cases of using ~/.profile as we have built and tested asdf with the specific setups as noted in the documentation - https://asdf-vm.com/#/core-manage-asdf - of which using ~/.profile is not one.

We have very clear documentation for specific machine configurations on our documentation site, so I would recommend following those closely as the order of steps matters (setting up asdf in your shell config before using it to add plugins). We also advise against using Homebrew as it can cause issues (again noted in the documentation). Perhaps a fresh install of asdf is in order.

Sorry, you're right. Somehow I have a bunch of plugins installed now:

$asdf plugin list
golang
minio
nodejs
postgres
redis
ruby
yarn

I honestly don't know how those got installed. I think maybe some bootstrap process in a work script might have done it? I only ever personally installed the ruby plugin myself.

maybe some bootstrap process in a work script might have done it

Perhaps advise the script author to log what it is configuring on your system.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Quintasan picture Quintasan  路  5Comments

jamesstidard picture jamesstidard  路  4Comments

rhiroyuki picture rhiroyuki  路  3Comments

johnjelinek picture johnjelinek  路  3Comments

peleteiro picture peleteiro  路  3Comments