asdf
asdf copied to clipboard
`asdf plugin add` should exit code 0 in most cases
Is your feature request related to a problem? Please describe.
asdf plugin add exits with code 2 if the plugin is already added. This isn't a great user experience for automation. From the perspective of the final result, the operation succeeded.
Describe the solution you'd like
Exit with code 0 if the plugin is already installed. Possibly check/warn if the current plugin is outdated?
Describe similar asdf features and why they are not sufficient n/a
Describe workarounds you've considered
asdf plugin add <name> || true
unfortunately this workaround is problematic in that if it fails for a different and legitimate reason, the script will not be aware.
Additional context n/a
@ghostsquad We have had a related discussion of this with #747
I believe a concensus was reached whereby we would remove non-zero exit codes on commands that did not fail, but did not change the state of things (due to an existing plugin as you suggest). As noted in https://github.com/asdf-vm/asdf/issues/747#issuecomment-691772544 the Issues and PRs that instituted this behaviour did not receive much feedback from our userbase (which was admittedly smaller) at the time.
@asdf-vm/core Are there any objections to addressing this issue with the proposition here https://github.com/asdf-vm/asdf/issues/747#issuecomment-70603025
EDIT: #66 also discusses this issue (I believe it was the first discussion)
If I'm reading the original issue (https://github.com/asdf-vm/asdf/issues/322) correctly, it seems that @the-mikedavis also preferred the status code of asdf plugin add to be 0.
Pinging @asdf-vm/core / @Stratus3D again, would there be any objections to a PR that changes the exit code back to 0? As mentioned in the discussion that @jthegedus linked above there seem to be more requests for a successful exit code than an error.
Totally agree. At least give us an option (e.g. similar to --failure-exit-code in rspec)
I made a comment in the other issue, but it looks like it was closed. My code is littered with asdf plugin add <blah> || true and error handling suffers because of it, because if there's a problem getting the plugin, that error is essentially ignored.
This is a popular request and have linked a PR that resolves this - hopefully it lands in v0.12.1 soon.
For now, the best workaround is manually checking exit codes:
asdf_plugin_add() {
asdf plugin add "$@" || {
local exit_code=$1
# If asdf detects that the plugin is already installed, it prints to standard error,
# then exits with a code of 2. We manually check this case, and return 0 so this
# this script remains idempotent, especially when `errexit` is set.
if ((exit_code == 2)); then
return 0
else
return $exit_code
fi
}
}
asdf_plugin_add <blah>
Theoretically, if Git returns with an exit code of 2 if cloning fails, or if a plugin exits with a code of 2, this will give a false positive, but the occurrence of said false positives is still drastically less than compared to without this workaround.