-
Notifications
You must be signed in to change notification settings - Fork 784
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
asdf install <plugin> <version>
should return a non-zero status code if already installed
#747
Comments
As you linked, we had this request for |
I would need to study the list of commands to give a more considered answer, but here's my precursory response:
I think the logic of calling commands should be if: then: In the example I posted, the resulting filesystem state is essentially identical to what it would be if the action had succeeded, but the actual action did not take place because it didn't need to. Perhaps you might conclude that those two things are not different enough to warrant a different code, and that returning a Here's an analogous example from a different domain— A A I think that there are going to be different opinions on this, and that's ok, but I argue that consistency is a global expectation. |
I agree we should be consistent. Do you know of any other Shell projects that have a specific exit code table?
|
@jthegedus Here's a very similar question on UNIX SE: https://unix.stackexchange.com/questions/110348/how-do-i-get-the-list-of-exit-codes-and-or-return-codes-and-meaning-for-a-comm One answer includes a link to info about |
#310 had a link to the BASH Advanced Scripting Guide which lists the following codes:
So whatever we come up with should use these first and avoid clashes for any custom codes we define. |
I'm -1 on this proposal and would rather keep non-zero exit codes for actual errors. I find it surprising behaviour when an idempotent command has a different exit code on subsequent runs. If the user wanted to avoid running a no-op command, they could instead check if the condition is already satisfied. E.g. if asdf plugin list | grep -q nodejs; then
echo "nodejs plugin already installed"
else
asdf plugin-add nodejs
fi But I find it hard to imagine a scenario where they'd actually want to do that. In most cases this simple code is sufficient # Install plugin or do nothing if already installed, and install latest nodejs version
asdf plugin-add nodejs && asdf install nodejs latest Because the end state matters, having the plugin be present. Doesn't matter if it was installed or not beforehand. By treating the no-op scenario as a failure, it forces users to add defensive code to their scripts even though the outcome of running the command is the same. With the non-zero exit code, the quickest workaround likely to be used is Unfortunately I don't think there is a standard to reference, you'll find common tools with opposite behaviour. E.g. BSD's $ echo $SHELL
/usr/local/bin/fish
$ chsh -s /usr/local/bin/fish
Changing shell for dideler.
Password for dideler:
chsh: no changes made
$ echo $?
0 And others, like Linux's $ useradd foo
$ useradd foo
useradd: user 'foo' already exists
$ echo $?
9 Ultimately I think it's more important that asdf be consistent with exit codes across its subcommands, rather than what the value of the exit code is. But wanted to chime in with a different perspective before this issue is addressed. |
Related to - asdf-vm/asdf#659 - asdf-vm/asdf#688 Note that `asdf install` may soon also return a non-zero code [1] which would require a similar patch in these language scripts. [1]: asdf-vm/asdf#747
@dideler Thanks for your input, feature requests too often only reflect the supporters of the changes. History of these ideas in this project:
Looking over the previous requests for this "different exit code" feature(s) we haven't had many people contribute support or otherwise, only the requester has been involved in the discussions. Perhaps this is indicative of it not being particularly important or us implementing changes too soon? @Stratus3D what are your thoughts? Given we reverted the last request of this type? @jsejcksn happy to hear further thoughts of yours since this initial request. I think we should be consistent. Given we have a different set of return codes for
Reverting the two existing seems easiest, but obviously breaking. This is definitely a problem that needs a resolution before we even think of a |
It seems that everyone agrees about consistency 🤝 Defining expectations is central to the decision-making process, because I think we all occasionally assume that everyone is sharing a perspective. @dideler brings up some interesting points:
I think the definitions of idempotence and no-op really depend on your expectations of what the command is, but I'm not sure everyone agrees about that. Here's a quote from issue #322:
In the description he states his assumption that what the command does "will result in asdf having that plugin". Let's apply that to the But first, I want to mention that I agree that the exit codes for a failure and a no-op (however that's defined) should not be the same. I think everyone agrees on this, but if not, please share your perspective! According to the quoted description above, in the author's perspective, what the Another point of view is making a distinction about what the command does—which is "actually install the plugin". In that view, if the plugin is already installed, the result of the command would be a no-op, but the command should not be considered to have succeeded because an installation didn't take place. This also yields information about the installation state of the plugin before running the command. In regard to consistency, I'd like to reference this SE question: Non-zero exit status for clean exit. Ultimately, I think that—in effort of simplicity and high compatibility with the rest of the UNIX ecosystem—it makes sense for |
Quoting @dideler
I'm building a deployment tool in my spare time and I can vote for that
For the sake of simplicity, we can stick with the existing behaviour. Closing this issue. Please feel free to continue discussion and reopen if appropriate. |
My only further input would be to consider reverting the other custom exit codes, otherwise we will receive this request again, and it's a reasonable request with the precedent set |
I believe that this perspective is a LOT less useful in real world situations. From a theoretical standpoint, it does seem useful to know what's going on behind the scenes. But when you actually get down to writing automation, the idea of "reconciliation" ends up being far superior to anything else. Another way to state this, is that as a user, I don't care about the how, I care about the what. In the case of how vs what as it pertains to what plugin is installed |
Similar to #322 — but for
asdf install <plugin> <version>
. It should exit with a non-zero status code if the version was already installed.The text was updated successfully, but these errors were encountered: