Skip to content

Commit 5e84789

Browse files
timjameetgoti07
authored andcommitted
Improve error handling in findFormParent (jenkinsci#26137)
* Improve error handling in findFormParent * Fix lint
1 parent 25cf2b3 commit 5e84789

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

war/src/main/webapp/scripts/hudson-behavior.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,21 +2302,31 @@ function ensureVisible(e) {
23022302
function findFormParent(e, form, isStatic) {
23032303
isStatic = isStatic || false;
23042304

2305+
const originalElement = e;
2306+
23052307
if (form == null) {
23062308
// caller can pass in null to have this method compute the owning form
23072309
form = e.closest("FORM");
23082310
}
23092311

2310-
while (e != form) {
2312+
while (e !== form) {
23112313
// this is used to create a group where no single containing parent node exists,
23122314
// like <optionalBlock>
2313-
var nameRef = e.getAttribute("nameRef");
2315+
const nameRef = e.getAttribute("nameRef");
23142316
if (nameRef != null) {
23152317
e = document.getElementById(nameRef);
23162318
} else {
23172319
e = e.parentNode;
23182320
}
23192321

2322+
if (!e) {
2323+
console.warn(
2324+
"findFormParent: reached document root without finding form",
2325+
originalElement,
2326+
);
2327+
return null;
2328+
}
2329+
23202330
if (!isStatic && e.getAttribute("field-disabled") != null) {
23212331
// this field shouldn't contribute to the final result
23222332
return null;
@@ -2522,6 +2532,7 @@ function buildFormTree(form) {
25222532

25232533
return true;
25242534
} catch (e) {
2535+
console.error("Form not submitted", e);
25252536
alert(e + "\n(form not submitted)");
25262537
return false;
25272538
}

0 commit comments

Comments
 (0)