Skip to content
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 plugin add should exit code 0 in most cases #841

Closed
ghostsquad opened this issue Dec 24, 2020 · 5 comments · Fixed by #1598
Closed

asdf plugin add should exit code 0 in most cases #841

ghostsquad opened this issue Dec 24, 2020 · 5 comments · Fixed by #1598

Comments

@ghostsquad
Copy link

ghostsquad commented Dec 24, 2020

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

@jthegedus
Copy link
Contributor

jthegedus commented Dec 24, 2020

@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 #747 (comment) 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 #747 (comment)

EDIT: #66 also discusses this issue (I believe it was the first discussion)

@strokirk
Copy link

If I'm reading the original issue (#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.

@cccCody
Copy link

cccCody commented Nov 1, 2021

Totally agree. At least give us an option (e.g. similar to --failure-exit-code in rspec)

@ghostsquad
Copy link
Author

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.

@hyperupcall
Copy link
Contributor

hyperupcall commented Jul 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants