-
Notifications
You must be signed in to change notification settings - Fork 245
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
[JENKINS-74964] Display error message when adding invalid certificate credentials #580
Conversation
…icate credentials
f7447bf
to
632611f
Compare
@@ -123,6 +123,7 @@ window.credentials.addSubmit = function (_) { | |||
.catch((e) => { | |||
// notificationBar.show(...) with logging ID could be handy here? | |||
console.error("Could not add credentials:", e); | |||
window.notificationBar.show("Credentials creation failed.", window.notificationBar["ERROR"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Add Credentials" popup does not handle HTML responses ("angry Jenkins"), causing the catch block to execute. Added notificationBar to inform the user about the failure(unexpected cases) in credential creation.
src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java
Outdated
Show resolved
Hide resolved
src/test/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImplFIPSTest.java
Outdated
Show resolved
Hide resolved
src/test/resources/com/cloudbees/plugins/credentials/impl/validCerts.pem
Show resolved
Hide resolved
src/test/resources/com/cloudbees/plugins/credentials/impl/validKey.pem
Outdated
Show resolved
Hide resolved
src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java
Outdated
Show resolved
Hide resolved
…n into JENKINS-74964
src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java
Show resolved
Hide resolved
* Descriptor#newInstanceImpl throws a LinkageError if the constructor throws any exception other | ||
* than HTTP response exceptions such as Descriptor.FormException. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK FormException
is not a RuntimeException
, and only `RuntimeException are not causing a LinkageError: https://github.com/jenkinsci/jenkins/blob/171097618b5b2b70ec3142e3efc80b4f2aff9601/core/src/main/java/hudson/model/Descriptor.java#L623 so
* Descriptor#newInstanceImpl throws a LinkageError if the constructor throws any exception other | |
* than HTTP response exceptions such as Descriptor.FormException. | |
* Descriptor#newInstanceImpl throws a LinkageError if the DataBoundConstructor or any DataBoundSetter throw any exception other | |
* than RuntimeException implementing HttpResponse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While FormException itself is not a RuntimeException, it is wrapped into HttpResponses, which is a RuntimeException,
https://github.com/jenkinsci/stapler/blob/master/core/src/main/java/org/kohsuke/stapler/RequestImpl.java#L691
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, that's incorrect. As for https://github.com/jenkinsci/jenkins/blob/171097618b5b2b70ec3142e3efc80b4f2aff9601/core/src/main/java/hudson/model/Descriptor.java#L622-L627 the Linkage error only can happen if the caught exception is RuntimeException AND HttpResponse. FormException is not in the catch clause, so it's not caught at all but directly thrown as stated in the method signature. The only way of getting a LinkageError is that the error is a NoSuchMethodException, an InstantiationException, an IllegalAccessException, an InvocationTargetException, or a RuntimeException that is not implementing HttpResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct that FormException is not explicitly in the catch clause of Descriptor#newInstanceImpl. However, my point was that FormException, when thrown, is wrapped into HttpResponses and HttpResponses is a RuntimeException.
Because of this wrapping, it ultimately satisfies the condition of being a RuntimeException and implementing HttpResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the comment
src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java
Show resolved
Hide resolved
src/main/java/com/cloudbees/plugins/credentials/CredentialsSelectHelper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with previous reviews/comments
JENKINS-74964
Testing done
Automated Unit Testing
Implemented unit tests to verify that the error messages are returned in the response on form submit
Manual Testing
Popup screen:
Submitter checklist