asdf plugin-add nodejs, for exampleYou should notice that the message that the plugin were already installed was an stderr
Since this is not actually an error, it should only return the message, without any error status. This is important because some automation scripts can't handle this.
For example, I'm developing an Ansible role that install a bunch of plugins on my workstation, and I need to manually ignore those errors. This can cause a lot of trouble.
It is being executed like if it was an error.
In you reproduction, are you "importing the Node.js release team's OpenPGP keys to main keyring" as in the plugin's instructions?
Yes, I've ran it. But the error I'm reporting has nothing to do with the plugin installation. I've just used nodejs as an example.
The problem is that asdf plugin-add command is returning as error if you try to add an existing plugin. This is complicated, because I've some automated scripts that keep my workstation updated.
Since adding an already existing plugin is not an error, this shouldn't happen
Fair enough. Thanks.
@odelucca This is being reverted in https://github.com/asdf-vm/asdf/pull/689 as the prior discussions, from essentially the same question, resulted in the addition of exit 2 for adding a plugin that already exists - see original issue https://github.com/asdf-vm/asdf/issues/322 and the actual discussion in the PR https://github.com/asdf-vm/asdf/pull/323
The recommendation for scripting is to capture the return value of the command and check for exit code 2 or to simply run the command with ... || true
If you have code that needs to verify that a plugin is installed, and don't care if it was already installed, something like this should do what you need:
status_code=$(asdf plugin-add <name> <url>)
if [ $status_code -eq 0 ] || [ $status_code -eq 2 ]; then
echo "Plugin is installed"
fi
Strange.
In my opinion exit with a code should be only used when an error occur. This is not actually an error and adding exit 1 or exit 2 makes harder to automated workstation setup.
For example, I use ansible to automate the installation of my tools. For every tool that I use, everytime I ran the install command it syncs my entire configs. Most times I try to reinstall every resource.
asdf-vm is the only tool that throws exit 1 when I try to install an already present plugin. For that instance I need to do a condition (like @Stratus3D mentioned) to avoid this messing up with my sync.
The problem with that is, if a real error occur, my automate setup will ignore it...
FYI for anyone following this thread when troubleshooting the same issue, the workaround in this comment is incorrect.
status_code=$(asdf plugin-add <name> <url>)
if [ $status_code -eq 0 ] || [ $status_code -eq 2 ]; then
echo "Plugin is installed"
fi
That'll capture command output, not the return code.
Instead in bash you'll want to check the value of $?. And if you have errexit set then you'll need to check it in way that ensures your script doesn't prematurely abort. Ideally I'd want asdf to not treat this scenario as an error (w.r.t. to exit code and output stream), so we don't have to write code like this in our scripts to handle the safe no-op.
You are right @dideler . Should be something like:
asdf plugin-add <name> <url>
status_code=$?
if [ $status_code -eq 0 ] || [ $status_code -eq 2 ]; then
echo "Plugin is installed"
fi
Most helpful comment
You are right @dideler . Should be something like: