-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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-53182] Uncaught TypeError: Cannot read property 'firstChild' of undefined - updateListBox #3645
Conversation
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.
Would be nice to understand what causes the issue. Could it be a custom Javascript from a theme?
No strong objection tho
status.innerHTML = ""; | ||
var followingTR = findFollowingTR(listBox, "validation-error-area"); | ||
if(followingTR!=undefined){ | ||
var status = findFollowingTR(listBox, "validation-error-area").firstChild.nextSibling; |
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.
Use the existing field instead of repeating findFollowingTR ()
?
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.
This has been taken care of by having an exception handler in place Oleg. Ideally, it reduces the overhead of using findFollowingTR () twice.
@@ -304,15 +304,17 @@ function findAncestorClass(e, cssClass) { | |||
function findFollowingTR(input, className) { | |||
// identify the parent TR | |||
var tr = input; | |||
while (tr.tagName != "TR") | |||
if(tr.tagName!=undefined){ | |||
while (tr.tagName != "TR") | |||
tr = tr.parentNode; |
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.
can the parentNode be undefined as well? I believe no, but just in case
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.
Make sense. So, I have added validation even on parentNode.
Question : Cause for this issue- Trying to use the method updateListBox() function in jelly for an internal plugin development. This function call caused the issue of uncaught 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.
Would be better to revert formatting changes.
Regarding the code itself, it would be great to get feedback from @jenkinsci/code-reviewers .
Looking forward to the feedback. "revert formatting changes" Can you help me understand more on this.? Thanks |
@sai-tirunagiri Many changes in the diff are just whitespace ones. E.g. compare this line with https://github.com/jenkinsci/jenkins/pull/3645/files?w=1 . The one without formatting contains only 10 added lines while the formatted diff displays 20 |
This is due to adding a level of indentation. Not doing that just hurts future legibility unnecessarily. |
OTOH the file currently has indentation of 4 spaces not 2, so this PR adds an inconsistency. |
@oleg-nenashev @daniel-beck , Thank you for the feedback on this. I have corrected the formatting issues. Please check and let me know. |
Thank you for the details. This helped me to understand. |
4fdf212 is bad. Please undo this. Lines should have their natural indentation, and if newly placed in a block, should be indented. |
@daniel-beck , does this change look good to you. |
while (tr.tagName != "TR") | ||
tr = tr.parentNode; | ||
|
||
// then next TR that matches the CSS | ||
do { | ||
tr = $(tr).next(); | ||
} while (tr != null && (tr.tagName != "TR" || !Element.hasClassName(tr,className))); | ||
|
||
return tr; |
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 don't understand why this line and preceding ones aren't indented.
@@ -304,15 +304,17 @@ function findAncestorClass(e, cssClass) { | |||
function findFollowingTR(input, className) { | |||
// identify the parent TR | |||
var tr = input; | |||
if(tr.tagName!=undefined && tr.parentNode!=undefined){ |
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.
Lack of spaces around parentheses and operators is inconsistent with the rest of the file (such as the one immediately below).
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.
This line of code has been removed. Since the exception handling is being done by the caller itself.
status = findFollowingTR(listBox, "validation-error-area").firstChild.nextSibling; | ||
if (status.firstChild && status.firstChild.getAttribute('data-select-ajax-error')) | ||
status.innerHTML = ""; | ||
}catch(e){ |
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.
Missing spaces
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.
Done with the changes as per the comment.
if (status.firstChild && status.firstChild.getAttribute('data-select-ajax-error')) { | ||
status.innerHTML = ""; | ||
var status; | ||
try{ |
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.
Missing spaces
Please try to adapt to the existing code style when editing a file (even if the entire code base might be a bit inconsistent overall). |
@daniel-beck , Apologies for not following the expected standards in the code. But did the changes as requested. Please review and let me know. I removed the undefined check and the operator from hudson-behaviour.js since, exception handling is being done on select.js itself (exception handling is done on the calling function) |
@oleg-nenashev , @daniel-beck any updates on this pull request. Thanks. |
Sorry, I totally missed the pings due to the conferences |
@oleg-nenashev @jenkinsci/code-reviewers.. any update on this pull request would be appreciated. Thanks. |
@daniel-beck @oleg-nenashev @kzantow - Please provide an update on this pull request. I am tired of dealing with this exception. |
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 still do not have any opinion about that. It still looks like suppressing a real defect in a custom plugin to me && I do not have enough Javascript expertise, so I am not ready to approve it
@@ -98,4 +103,4 @@ Behaviour.specify("SELECT.select", 'select', 1000, function(e) { | |||
} | |||
}); | |||
}); | |||
}); | |||
}); |
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.
}); | |
}); | |
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.
Is there linting in place to guarantee newline at end of file?
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.
@@ -3053,4 +3051,4 @@ var notificationBar = { | |||
if (!options.sticky) | |||
this.token = window.setTimeout(function(){self.hide();},this.DELAY); | |||
} | |||
}; | |||
}; |
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.
}; | |
}; | |
status.innerHTML = ""; | ||
} | ||
catch(e) { | ||
console.log(e); |
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.
If it's a critical error it should probably be printed out with a console.error
or console.warn
status.innerHTML = ""; | ||
} | ||
catch(e) { | ||
console.log(e); |
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.
this doesn't really solve the problem, does it? just logs instead of throw
ing?
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 suggest:
- find out what scenario causes this problem
and - either extract out checks for
.firstChild
and.nextSibling
or change a selector such that it fixes the root cause of the problem.
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 might be wrong tho |
@oleg-nenashev - Thanks for the update. I will wait for it then. |
@oleg-nenashev huh? That is this PR. Which do you mean? |
@oleg-nenashev: did you mean #3869? |
I have too many things in too many states to be sure. I also have one thing which will significantly rework how hudson-behavior and these jelly files handle things (#3859). I'm not sure which change is likely to be relevant. I also have a couple of changes which adjust handling of empty children. But yes, I do think that checking again after a release would be a good idea. |
@sai-tirunagiri Would you be able to test your plugin with https://repo.jenkins-ci.org/incrementals/org/jenkins-ci/main/jenkins-war/2.164-rc27955.2f8b557a3bac/ to confirm whether the issue is fixed by the already integrated fixes? |
So, I still I hit this. In my case, the select is in
The select is for:
In this case, the problem is that the select is not generated by jenkinsci/jenkins jelly, it's from: https://github.com/jenkinsci/mercurial-plugin/blob/288e4dd0a629c7071b09305d4c238ff117fd7187/src/main/resources/hudson/plugins/mercurial/MercurialSCM/config.jelly#L20 The right fix is thus not to hack the JS here in jenkins the way that's being suggested. It would be to instead to add an extra attribute to the select, check for that, and then only try to run this code if that attribute is present. 👎 More precisely, it's this widget I'm still looking through, but it really feels like something is responsible for the field not having the item ... |
@oleg-nenashev : Its still the same.
|
@jsoref : I did follow your inputs and tried organizing the config.jelly a bit. after doing these changes in jelly..
ended up getting the below error.
any clue.? |
@sai-tirunagiri: sorry, I'm still looking into this. |
FWIW, I've put in 13cd57d (into my PR) which I think will limit the fallout from errors like this. It isn't a fix for the underlying problem, but I think it's a helpful step for resiliency. |
Thank you @jsoref .. So, this will be available to me in the next release of Jenkins is it? |
No. I'm still tinkering with it. (I'm going to include exception logging, otherwise debugging is painful.) |
Agreed. Please do keep this thread updated as its an important patch for us. @jsoref |
@jsoref : we do have the same issue with different users. |
@oleg-nenashev Could you clarify why you put this on-hold? To wait for the response whether it's already fixed that was provided within a day? |
This kind of error message is a longstanding problem in Jenkins. There is not a single root cause, but rather a variety of mistakes such as malformed plugin Jelly files (one example: forgetting to wrap some elements in a table row), unexpected null values or Java exceptions, etc. which are not being properly detected and recovered from gracefully. Merely printing a JavaScript error is unlikely to provide meaningful diagnostics. If the specific instance of the problem motivating this particular issue is reproducible, then you need to track down the root cause and add proper error handling at the source. Additionally, I would expect fixes like this to be accompanied by a regression test, probably using HtmlUnit. |
@sai-tirunagiri Would you have time to come back on this PR? |
In the current state, I think it doesn't really solve the issue but hides it somehow. We should work in fixing the real problem. |
We are proposing this closure given there's been no follow up for some time. |
Yes, we can close this. I did a workaround using ajax in jelly which seems to have sorted this problem. But, we still need to find out the exact root cause of this issue. Thanks. |
See JENKINS-53182.
Proposed changelog entries
Submitter checklist
* Use the
Internal:
prefix if the change has no user-visible impact (API, test frameworks, etc.)