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

fix: insert error handling in list-all & download plugin scripts #881

Merged
merged 10 commits into from May 19, 2021

Conversation

laidbackware
Copy link
Contributor

@laidbackware laidbackware commented Mar 3, 2021

Summary

This fix will check if a plugin does not exit 0 when calling list-all or download. In the case of an error it will print all stdout and stderr returned by the plugin and then the list all script will exit 1.

Without this fix, it is not possible to test a plugin using CI and get reliable results, as errors are not handled.

Fixes: This fixes #880 and #886

Other Information

This has been tested on Linux and MacOS to be working as expected.

Thank you for contributing to asdf!

check the plugin return code is 0
if not print all outputs from plugin and exit 1
@laidbackware laidbackware requested a review from a team as a code owner March 3, 2021 18:00
@Stratus3D
Copy link
Member

Thanks for the PR! I think there are a couple things we need to do before merging this:

  • Write tests for list-all failures, and assert that the command works as expected
  • When plugin list-all fails, print a line before the plugin output with something along the lines of Plugin <plug name>'s list-all callback script failed with output:

Thanks for the PR! This is a good improvement.

refactor testing to detect broken plugins
add list-all command to testing
refactor 2 list tests to include broken plugin
split some test asertions to aid readability
@laidbackware
Copy link
Contributor Author

laidbackware commented Mar 15, 2021

Refactored to include tests - which included fixed 2 existing tests.
I broke some affected string tests out to separate lines to aid readability and prevent long lines.
Added check to install script to allow for plugin download to cleanly exit.
The returncode is collected outside the subshell with no default set prior, as if the download/install block doesn't run the return code of the if command will be captured. The script will then tidy up if either download or install do not exit clearnly.

@laidbackware laidbackware changed the title insert error handling in list-all insert error handling in list-all and download plugin scripts Mar 15, 2021
@Stratus3D
Copy link
Member

@laidbackware changes look good! I did leave two comments, one about printing failure output to STDERR, and the other is a question about the tests. Let me know if you will address these comments or if you would like me to make the STDERR change before merging.

@laidbackware
Copy link
Contributor Author

laidbackware commented Mar 30, 2021

@Stratus3D I have also been thinking about another edge case which I'd be interested on your thoughts on before implementing.

This change is currently written to redirect all STDOUT and STDERR data to a single variable when calling list-all. This is fine if the plugin generates an error, but may cause issues if a plugin uses a tool which happens to write to STDERR under normal operation as some linux tools do.

return_code=0 && versions=$(bash "${plugin_path}/bin/list-all" 2>&1) || return_code=$?

In this case it would skew the output of the asdf command.

The only clean solution I can think of to split the output is to acutally call the list-all script twice. Once just capturing STDOUT which is printed if no errrors occur, but if there is an error it is run a second time to capture STDOUT and STDERR.

What do you think?

Copy link
Contributor

@jthegedus jthegedus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @Stratus3D ?

update dummy plugin to include error to ignore
update broken plugin to add stderr output
update list-all test to check for stderr on failure
update list-all test to check for no stderr on success
@laidbackware
Copy link
Contributor Author

@Stratus3D @jthegedus I think I've solved the issue I mentioned previously without calling the plugin twice. I was concerned that if there were network timeouts, calling the plugin twice could be worse for the user.
Now command-list-all.bash contains a function which splits stdout and stderr into separate variables. When the plugin list-all script exits with code 0, then stderr is ignored and when it exits with a non-zero code stderr then stdout is printed. I've also added tests to ensure stderr is ignored when sucessful and printed when unsuccessful.
All CI tests look good on my end.

@jthegedus jthegedus changed the title insert error handling in list-all and download plugin scripts fix: insert error handling in list-all & download plugin scripts May 19, 2021
@jthegedus jthegedus merged commit a7d3661 into asdf-vm:master May 19, 2021
@jthegedus
Copy link
Contributor

Thanks very much for contributing this @laidbackware Really appreciate it 😄

@Stratus3D
Copy link
Member

Sorry @laidbackware for never responding, looks great :)

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

Successfully merging this pull request may close these issues.

list-all does not allow for plugin to error
3 participants