Skip to content
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

Closed
wants to merge 7 commits into from

Conversation

sai-tirunagiri
Copy link

See JENKINS-53182.

Proposed changelog entries

  • Fix - Uncaught TypeError: Cannot read property 'firstChild' of undefined - updateListBox

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • [n/a] Appropriate autotests or explanation to why this change has no tests
  • [n/a] For dependency updates: links to external changelogs and, if possible, full diffs

Copy link
Member

@oleg-nenashev oleg-nenashev left a 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;
Copy link
Member

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 () ?

Copy link
Author

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;
Copy link
Member

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

Copy link
Author

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.

@sai-tirunagiri
Copy link
Author

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.

Copy link
Member

@oleg-nenashev oleg-nenashev left a 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 .

@sai-tirunagiri
Copy link
Author

Looking forward to the feedback.

"revert formatting changes" Can you help me understand more on this.? Thanks

@oleg-nenashev
Copy link
Member

@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

@daniel-beck
Copy link
Member

@oleg-nenashev

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.

@daniel-beck
Copy link
Member

OTOH the file currently has indentation of 4 spaces not 2, so this PR adds an inconsistency.

@sai-tirunagiri
Copy link
Author

@oleg-nenashev @daniel-beck , Thank you for the feedback on this. I have corrected the formatting issues. Please check and let me know.

@sai-tirunagiri
Copy link
Author

@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

Thank you for the details. This helped me to understand.

@daniel-beck
Copy link
Member

4fdf212 is bad. Please undo this. Lines should have their natural indentation, and if newly placed in a block, should be indented.

@sai-tirunagiri
Copy link
Author

@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;
Copy link
Member

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){
Copy link
Member

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).

Copy link
Author

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){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces

Copy link
Author

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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces

@daniel-beck
Copy link
Member

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).

@sai-tirunagiri
Copy link
Author

@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)

@sai-tirunagiri
Copy link
Author

@oleg-nenashev , @daniel-beck any updates on this pull request. Thanks.

@oleg-nenashev
Copy link
Member

Sorry, I totally missed the pings due to the conferences

@oleg-nenashev
Copy link
Member

No opinion, now it just suppresses exceptions.
CC @kzantow @recena and other @jenkinsci/code-reviewers with JS expertise

@sai-tirunagiri
Copy link
Author

@oleg-nenashev @jenkinsci/code-reviewers.. any update on this pull request would be appreciated. Thanks.

@sai-tirunagiri
Copy link
Author

@daniel-beck @oleg-nenashev @kzantow - Please provide an update on this pull request. I am tired of dealing with this exception.

Copy link
Member

@oleg-nenashev oleg-nenashev left a 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) {
}
});
});
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
});

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?

Copy link
Contributor

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);
}
};
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
};

@oleg-nenashev oleg-nenashev changed the title Jenkins 53182 Uncaught TypeError: Cannot read property 'firstChild' of undefined - updateListBox [JENKINS-53182] Uncaught TypeError: Cannot read property 'firstChild' of undefined - updateListBox Jan 28, 2019
status.innerHTML = "";
}
catch(e) {
console.log(e);

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);
Copy link
Contributor

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 throwing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest:

  1. find out what scenario causes this problem
    and
  2. either extract out checks for .firstChild and .nextSibling or change a selector such that it fixes the root cause of the problem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jenkins console error:-
image

jelly config file
image

So, this error is caused by updateListBox function.. Any suggestions on fixing this would be great.

Fyi... the same works totally fine on jenkins verion 2.7.3

@oleg-nenashev
Copy link
Member

@jsoref has proposed another fix in #3645 . I believe that fix solves this issue as well

@oleg-nenashev oleg-nenashev added the proposed-for-close There is no consensus about feasibility of this PR, and maintainers do not see a way forward for it label Jan 31, 2019
@oleg-nenashev
Copy link
Member

I might be wrong tho

@sai-tirunagiri
Copy link
Author

@oleg-nenashev - Thanks for the update. I will wait for it then.

@jglick
Copy link
Member

jglick commented Feb 7, 2019

@jsoref has proposed another fix in #3645

@oleg-nenashev huh? That is this PR. Which do you mean?

@jsoref
Copy link
Contributor

jsoref commented Feb 7, 2019

@oleg-nenashev: did you mean #3869?

@jsoref
Copy link
Contributor

jsoref commented Feb 7, 2019

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.

@oleg-nenashev oleg-nenashev added on-hold This pull request depends on another event/release, and it cannot be merged right now and removed proposed-for-close There is no consensus about feasibility of this PR, and maintainers do not see a way forward for it labels Feb 8, 2019
@oleg-nenashev
Copy link
Member

@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?

@jsoref
Copy link
Contributor

jsoref commented Feb 8, 2019

So, I still I hit this.

In my case, the select is in
#main-panel > form > div > div:nth-child(133) > div.setting-main > div > div:

<div name="libraries" class="repeated-chunk to-be-removed">
  <div class="dd-handle">Library</div>
...
<!-- #main-panel > form > div > div:nth-child(133) > div.setting-main > div > div > div:nth-child(2) > div:nth-child(39) > div.setting-main > div > div > select -->
<select fillurl="/descriptorByName/hudson.plugins.mercurial.MercurialSCMSource/fillCredentialsIdItems" filldependson="source" name="_.credentialsId" class="setting-input  select  credentials-select" value="">
</select>

The select is for:

<div class="setting-name">Credentials
  <span class="setting-help">
    <a helpurl="/descriptor/hudson.plugins.mercurial.MercurialSCMSource/help/credentialsId" href="#" class="help-button"><img
src="/static/34c69582/images/16x16/help.png" alt="Help for feature: Credentials" style="width: 16px; height: 16px; " class="icon-help icon-sm"
    ></a>
  </span>
</div>

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
https://github.com/jenkinsci/credentials-plugin/blob/07728f1a2f16046f27a3e84585356d4b10359c6d/src/main/resources/lib/credentials/select.jelly

I'm still looking through, but it really feels like something is responsible for the field not having the item ...

@sai-tirunagiri
Copy link
Author

sai-tirunagiri commented Feb 9, 2019

@oleg-nenashev : Its still the same.

Uncaught TypeError: Cannot read property 'firstChild' of undefined
    at updateListBox (select.js:8)
    at select.js:79
    at h (hudson-behavior.js:1304)
    at refillOnChange (hudson-behavior.js:1319)
    at select.js:77
    at Array.forEach (<anonymous>)
    at behavior.js:111
    at Array.forEach (<anonymous>)
    at behavior.js:107
    at Array.forEach (<anonymous>)

@sai-tirunagiri
Copy link
Author

sai-tirunagiri commented Feb 9, 2019

@jsoref : I did follow your inputs and tried organizing the config.jelly a bit. after doing these changes in jelly..

<f:entry field="configName" title="Choose Configuration Name">
 <f:select onchange="updateListBox('team_info','descriptorByName/org.jenkinsci.plugins.ctc.TestAutomationBuilder/teamInfo?value='+encode(this.value))"/>
</f:entry>

<f:entry field="teamInfo" title="Choose Your Team">
    <f:select name="team_info" id="team_info"/>
</f:entry>

ended up getting the below error.

Uncaught TypeError: Cannot read property 'tagName' of undefined
    at findFollowingTR (hudson-behavior.js:307)
    at updateListBox (select.js:8)
    at HTMLSelectElement.onchange (configure:1)

any clue.?

@jsoref
Copy link
Contributor

jsoref commented Feb 11, 2019

@sai-tirunagiri: sorry, I'm still looking into this.

@jsoref
Copy link
Contributor

jsoref commented Feb 14, 2019

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.

@sai-tirunagiri
Copy link
Author

Thank you @jsoref .. So, this will be available to me in the next release of Jenkins is it?

@jsoref
Copy link
Contributor

jsoref commented Feb 17, 2019

No. I'm still tinkering with it. (I'm going to include exception logging, otherwise debugging is painful.)

@sai-tirunagiri
Copy link
Author

Agreed. Please do keep this thread updated as its an important patch for us. @jsoref

@sai-tirunagiri
Copy link
Author

@jsoref : we do have the same issue with different users.

image

@daniel-beck
Copy link
Member

@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?

@jglick
Copy link
Member

jglick commented Apr 19, 2019

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.

@alecharp
Copy link
Member

alecharp commented Aug 1, 2019

@sai-tirunagiri Would you have time to come back on this PR?

@varyvol
Copy link

varyvol commented Aug 29, 2019

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.

@oleg-nenashev oleg-nenashev added the stalled The PR is reasonable and might be merged, but it is no longer active. It can be taken over by other label Aug 29, 2019
@varyvol
Copy link

varyvol commented Nov 14, 2019

We are proposing this closure given there's been no follow up for some time.

@varyvol varyvol added the proposed-for-close There is no consensus about feasibility of this PR, and maintainers do not see a way forward for it label Nov 14, 2019
@sai-tirunagiri
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-hold This pull request depends on another event/release, and it cannot be merged right now proposed-for-close There is no consensus about feasibility of this PR, and maintainers do not see a way forward for it stalled The PR is reasonable and might be merged, but it is no longer active. It can be taken over by other
Projects
None yet
9 participants