[JENKINS-75378] Adding a CLI command listener#10382
[JENKINS-75378] Adding a CLI command listener#10382krisstern merged 18 commits intojenkinsci:masterfrom
Conversation
core/src/main/java/hudson/cli/listeners/DefaultCliListener.java
Outdated
Show resolved
Hide resolved
aneveux
left a comment
There was a problem hiding this comment.
Looks very good to me, thanks a lot! ❤️
| } else if (e instanceof AccessDeniedException) { | ||
| exitCode = 6; | ||
| printError(e.getMessage()); | ||
| } else if (e instanceof BadCredentialsException) { |
There was a problem hiding this comment.
Looks like BadCredentialsException is not longer possible inside CLICommand#main, note {set/get}TransportAuth2:
-
for HTTP or WebSocket the BadCredential is thrown/handled in the filters. When using command line
-auth user:passbasic auth : BasicHeaderAuthenticator / AbstractUserAuth. -
for SSH auth errors (not a BadCredentials) is also handled before executing the command (PublicKeyAuthenticatorImpl / UserAuthNamedFactory).
b1803a9 I can't find CliAuthenticationTest, may not apply anymore.
EDIT: this branch is only possible if a CLICommand implementation throws a BadCredentialsException,
| this.locale = locale; | ||
| CmdLineParser p = getCmdLineParser(); | ||
|
|
||
| final String correlationId = UUID.randomUUID().toString(); |
There was a problem hiding this comment.
suggestion: The introduction of correlationId common to all events could be highlighted in the PR description.
There was a problem hiding this comment.
At this point correlationId is only used in BadCredentialsException handling. (where the original randomUUID comes form)
|
Looks good, thanks @apuig ! |
clarify interface about onComplete not always success remove exitCode from onException remove fire methods args in CliContext rename CliListenerTest
|
please note: the failing test
reference CLI, but master also experience problems with this test class |
|
Hello @jenkinsci/core-pr-reviewers 👋 It looks like since @apuig is not a member (yet) of the jenkinsci organization, he cannot ask you for reviews on this PR, and AFAICT, I cannot add a team as reviewers on his PR either. Thanks a lot ❤️ |
|
/label ready-for-merge This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback. |
| * @param context Information about the command being executed | ||
| * @param t Any error during the execution of the command. | ||
| * */ | ||
| default void onException(@NonNull CliContext context, @NonNull Throwable t) {} |
There was a problem hiding this comment.
Misleading name if it takes a Throwable? #onError maybe?
There was a problem hiding this comment.
I renamed onError to onException to better emphasize that onComplete also handles cases where run returns an error code.
#10382 (comment)
I'm open to suggestions, but I prefer to avoid using onError.
There was a problem hiding this comment.
JUnit has failures (unsatisfied assertions) and errors (unexpected exceptions thrown), perhaps we could use one term to refer to "did not succeed" and use the other for "this threw up"?
daniel-beck
left a comment
There was a problem hiding this comment.
Looks great 👍 Thanks!
Would be nice to have the missing test, and perhaps checking the onException name, but not blocking. I'll leave it to @apuig whether to address those.
|
Thanks for the review @daniel-beck . With your hint, I was able to write the missing test. The current failing test Would it be possible to have another review to put back the |
|
I'm going to start the countdown here, but welcome further feedback on the renamed method before we're cementing it forever 😉 |
| * Invoked after command execution. | ||
| * | ||
| * @param context Information about the command being executed. | ||
| * @param exitCode Exit code returned by the implementation of {@link CLICommand#run()}. |
There was a problem hiding this comment.
How would this not always be zero? I am presuming you either get onCompleted, with zero, or onThrowable?
Never mind, a command could return some nonzero code without throwing an exception.
There was a problem hiding this comment.
yeah, that was the tricky part on the naming, indeed onCompleted will handle controlled exit codes from implementations
There was a problem hiding this comment.
The Javadoc could probably be clarified to emphasize that either onCompleted or onThrowable is called.
See JENKINS-75378.
The default implementation mimics the current logs in CLICommand.
Testing done
Executed commands using cli.jar using different transports
Proposed changelog entries
Proposed changelog category
/label rfe
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@mention
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered (see query).