Skip to content

Commit

Permalink
[JENKINS-73771] do not loose the formField in the response
Browse files Browse the repository at this point in the history
Implements a crude way to not loose the important part that is the form
field.

This is a quick and dirty approach, a complete fix should also take into
account the describable being bound as in a nested page like
/manage/configure a field name may not even be unique.

However for now this makes the situation less bad without introducing
debt.
  • Loading branch information
jtnord committed Sep 13, 2024
1 parent d5271c8 commit 5edbfeb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1303,14 +1303,17 @@ public String getFormField() {
return formField;
}

private String errorMessage() {
return getFormField() + ": " + getMessage();
}

@Override
public void generateResponse(StaplerRequest2 req, StaplerResponse2 rsp, Object node) throws IOException, ServletException {
if (FormApply.isApply(req)) {
FormApply.applyResponse("notificationBar.show(" + quote(getMessage()) + ",notificationBar.ERROR)")
FormApply.applyResponse("notificationBar.show(" + quote(errorMessage()) + ",notificationBar.ERROR)")
.generateResponse(req, rsp, node);
} else {
// for now, we can't really use the field name that caused the problem.
new Failure(getMessage()).generateResponse(req, rsp, node, getCause());
new Failure(errorMessage()).generateResponse(req, rsp, node, getCause());
}
}
}
Expand Down

0 comments on commit 5edbfeb

Please sign in to comment.