Skip to content

Exit code 1 for any failed checks#125

Merged
schlessera merged 10 commits intowp-cli:masterfrom
flinthillsdesign:check-exit-code
Nov 27, 2017
Merged

Exit code 1 for any failed checks#125
schlessera merged 10 commits intowp-cli:masterfrom
flinthillsdesign:check-exit-code

Conversation

@davegaeddert
Copy link
Copy Markdown
Contributor

I think this should mostly make sense. The gist is that if any checks fail in a wp doctor check command, then it should use the exit code 1. As far as I could tell, it was always exiting with 0 regardless of whether the checks succeeded or not. I think this would make the command more useful, especially for automated systems/scripts.

I had a little trouble testing the STDERR message, so that should probably be checked if this makes sense and can be merged.

Thanks, this is an awesome wp-cli tool!

$message = 1 === $check_count ? "1 check reports 'error'." : "${check_count} checks report 'error'.";
WP_CLI::error( $message );
} else {
exit( 1 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should use WP_CLI::halt( 1 ); so we can avoid exiting if we need to.

@danielbachhuber
Copy link
Copy Markdown
Member

The gist is that if any checks fail in a wp doctor check command, then it should use the exit code 1. As far as I could tell, it was always exiting with 0 regardless of whether the checks succeeded or not.

@wp-cli/committers What do you think about this proposed change?

I don't remember my original intent in always using exit(0), even when there are failures. Personally, I'm open to this change, but it would be a significant change and potentially break existing user scripts. It'd be great if there was some prior art we could base this from.

* upstream/master:
  Revert "Validate MIME type against extensions"
@schlessera
Copy link
Copy Markdown
Member

I think it makes sense to have a non-zero exit code on error. As an example, you could then use wp doctor from within a deployment script and halt/rollback the deployment if the built site happens to have issues.

If the compatibility break is an issue, we should bump the major version. We're at v0.1.0, though, which would signal that the public API is not yet finalized anyway.

I'm 👍 for this change.

if ( ! empty( $results_with_error ) ) {
if ( 'table' === $assoc_args['format'] ) {
$check_count = count( $results_with_error );
$message = 1 === $check_count ? "1 check reports 'error'." : "${check_count} checks report 'error'.";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we update the tests to include coverage for this output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had some trouble with that for some reason. But I probably figured a few things out since then so I'll try again as soon as I can.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@danielbachhuber just a heads up -- the issue was that Formatter removes $assoc_args['format'], so I had to change it do that check before formatter runs. Don't know if there's a specific reason it works that way, but it caught me off guard.
https://github.com/wp-cli/wp-cli/blob/master/php/WP_CLI/Formatter.php#L37

@miya0001
Copy link
Copy Markdown
Member

I like it too. 👍

@davegaeddert
Copy link
Copy Markdown
Contributor Author

Could somebody poke travis to run the tests? I can't come up with anything else to commit to trigger it...

@gitlost
Copy link
Copy Markdown

gitlost commented Nov 22, 2017

Probably easiest if you do it (aka I don't know how to do it) - a suggestion would be to put a space before the opening curly brace here $results = array_filter( $results, function( $check ){ (or do any random comment/whitespace change - it can always be immediately undone after the build triggers)....

@gitlost
Copy link
Copy Markdown

gitlost commented Nov 22, 2017

Okay that's not working - I notice you have merge conflicts in your own branch https://github.com/flinthillsdesign/doctor-command/pull/2, maybe that's confusing Travis - maybe do a git fetch upstream and git merge upstream/master and resolve the conflicts and push to get things moving...

* upstream/master:
  Fix @var tag for check->_message
  Add value_is_not setting to option value check
  Move the options header for check command docs
  Add `--format=count` to supported formats
@davegaeddert
Copy link
Copy Markdown
Contributor Author

Thanks @gitlost, I closed my PR and merged upstream/master...something there got it going again.

@davegaeddert
Copy link
Copy Markdown
Contributor Author

Alright, the tests are passing so I think I'm done here. Let me know if there's anything else I need to do. Thanks!

@danielbachhuber
Copy link
Copy Markdown
Member

Looks good to me. Requested a second review from @schlessera

@schlessera schlessera merged commit 9656de3 into wp-cli:master Nov 27, 2017
@schlessera
Copy link
Copy Markdown
Member

Merged, thanks for the PR, @davegaeddert !

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants