Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 476713

Summary: TypeError: Cannot read property 'Location' of undefined
Product: [ECD] Orion Reporter: guji muun <gujiman>
Component: ClientAssignee: Michael Rennie <Michael_Rennie>
Status: RESOLVED FIXED QA Contact: Eric Moffatt <emoffatt>
Severity: normal    
Priority: P3 CC: curtis.windatt.public, Michael_Rennie, Silenio_Quarti
Version: 10.0   
Target Milestone: 10.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description guji muun CLA 2015-09-05 22:15:05 EDT
when i place my mouse over a javascript function name in the client version of Orion (built-codeEdit) i get the following error:

Error computing hover tooltip
TypeError: Cannot read property 'Location' of undefined
    at Object.internalRegistry.handleServiceError (http://localhost/projects/built-codeEdit/code_edit/built-codeEdit.js:4021:29)
    at Object._messageHandler [as handler] (http://localhost/projects/built-codeEdit/code_edit/built-codeEdit.js:3249:55)
    at _channelHandler (http://localhost/projects/built-codeEdit/code_edit/built-codeEdit.js:4063:25)
    at http://localhost/projects/built-codeEdit/code_edit/built-codeEdit.js:4073:21
    at Array.some (native)
    at _messageHandler (http://localhost/projects/built-codeEdit/code_edit/built-codeEdit.js:4071:23)

To re-create this error enter the following text into the editor:

var f = "foo";
f.charAt(2);

Now place you mouse over 'charAt'. The tooltip does not popup and the console will log this error.

However this works perfectly for the server version of orion.
Comment 1 guji muun CLA 2015-09-06 14:28:39 EDT
ive found a possible fix??

open file 'hover.js' and got line 261 and change the following line:

that.resolver.setSearchLocation(meta.parents[meta.parents.length - 1].Location);

into the following:

if (meta.parents[meta.parents.length - 1] === undefined){
    that.resolver.setSearchLocation(meta.Location);
}else{
    that.resolver.setSearchLocation(meta.parents[meta.parents.length - 1].Location); 
}


i think the problem here was that when the 'computeHoverInfo' function is called from within 'javascriptPlugin.js' then 'meta.parents[meta.parents.length - 1]' doesn't exist in the client version of orion, but only exist in the server version.
Comment 2 Curtis Windatt CLA 2015-09-09 16:43:42 EDT
It makes sense that no parents can be found for the file metadata when running in the code edit widget.  I'm surprised that trying to retrieve an array entry from an undefined (or an empty array with index -1) simply returns undefined rather than failing altogether.

The question is when no parent folder structure is available whether setting search location to meta.Location as you suggested is beneficial or if we should simply return null.

Mike, any thoughts?
Comment 3 Michael Rennie CLA 2015-09-10 14:49:16 EDT
(In reply to Curtis Windatt from comment #2)
> It makes sense that no parents can be found for the file metadata when
> running in the code edit widget.  I'm surprised that trying to retrieve an
> array entry from an undefined (or an empty array with index -1) simply
> returns undefined rather than failing altogether.
> 
> The question is when no parent folder structure is available whether setting
> search location to meta.Location as you suggested is beneficial or if we
> should simply return null.
> 
> Mike, any thoughts?

I think this would be a better solution:

if(Array.isArray(meta.parents) && meta.parents.length > 0) {
  that.resolver.setSearchLocation(meta.parents[meta.parents.length - 1].Location);	
}

The reaosn being is that if we set the search scope to be the current file (where we are hovering), we will effectovely turn off hover nav, since the resolver will never search outside of the file.

I pushed the mentioned fix to master:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=9d97b6227b418a55ec7ee1d87714ad6afc685991