Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347795 - JSON parse errors on index.html
Summary: JSON parse errors on index.html
Status: RESOLVED FIXED
Alias: None
Product: Orion
Classification: ECD
Component: Client (show other bugs)
Version: 0.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 0.2   Edit
Assignee: Simon Kaegi CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-31 10:35 EDT by Simon Kaegi CLA
Modified: 2011-09-01 11:41 EDT (History)
2 users (show)

See Also:
john.arthorne: review+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Kaegi CLA 2011-05-31 10:35:07 EDT
In FF4/firebug I see -- 

SyntaxError: JSON.parse
return projectsPref ? JSON.parse(projectsPref) : null;   -- line 50 (index.html)

I don't think we're handling settting/getting projectsPref correctly.
Comment 1 Susan McCourt CLA 2011-05-31 13:44:32 EDT
This code has worked in the past, but it seems like something weird is going on when the preferences are cleared.  I stepped through it and appears to me that there is some gibberish being returned by the prefs service.

This is the code:

serviceRegistry.getService("orion.core.preference").then(function(service) {
				return service.getPreferences("/window/recent");
			}).then(function(prefs){
				var projectsPref = prefs.get("projects");
				return projectsPref ? JSON.parse(projectsPref) : null;


The "prefs" returned by getPreferences("/window/recent") is an empty object, { }
Not too surprising if there are no values there.
But then the request 
   prefs.get("projects");

returns this:

"["8","\"","}","]"

So the attempt to parse it fails. Where did this string come from?
The code assumes that if there is something returned by prefs.get("projects") that it is valid json.

I then navigated to a project (so that a new location would be set in this preference).  Then the preference node value is:

"["8","\"","}","]",{"location":"/file/e/?depth=1","name":"m8"}]"

That second value looks good.
So the question is, where is that first string coming from for the empty pref node.  

I think this is a prefs service bug????
Comment 2 Simon Kaegi CLA 2011-06-06 10:50:01 EDT
The projects pref in this case does not need to be parsed as the preferences service has already done that and the setter did not stringify the perferences prior to setting them. I have a small patch for review.

 I manually cleared my old user preferences and no longer have problems but I would like to try this in a clean build to make sure I am really getting this problem.
Comment 3 Simon Kaegi CLA 2011-06-06 14:55:17 EDT
I'm no longer seeing the parse error but when walking through with the debugger am still seeing something like [""","}","]", ...correct project json...]. I'll dig further here as something is clearly messed up and will eventually come back to bite us.
Comment 4 Simon Kaegi CLA 2011-06-06 18:35:31 EDT
There is a problem in the PreferencesServlet where we are ending up losing JSON type information when we serialize our values as strings. When we go to re-get them we always treat them as strings. I'm not sure if this is by design but I don't think we want to change this right now.

Favorites.js is using a check to determine if a preference has been returned as a string and if so will JSON.parse it. This is why favorites has never been broken. I've made it so the "/windows/recent/projects" preference uses the same logic.

I'll open a separate bug to figure out what we want to do server-side.
Comment 5 Simon Kaegi CLA 2011-06-06 18:36:17 EDT
Fixed in HEAD.

Mark reviewed this latest fix.