From 5edbfebb9f6d77b49d250dc6c0d79ff8e5b2d254 Mon Sep 17 00:00:00 2001 From: James Nord Date: Fri, 13 Sep 2024 21:04:41 +0100 Subject: [PATCH] [JENKINS-73771] do not loose the formField in the response 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. --- core/src/main/java/hudson/model/Descriptor.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index e2067bfc6944..b4aa87b40543 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -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()); } } }