tern.java icon indicating copy to clipboard operation
tern.java copied to clipboard

json parse exception

Open gamerson opened this issue 10 years ago • 19 comments

With the aui plugin enabled and in .js file if I do code assist like :

AUI().use('aui-base', function(A) { new A. });

it will get no proposals and in the tern console I get the following error:

-----------------------------------
Tern request#:
{"files":[{"name":"docroot/js/main.js","text":"AUI().use('aui-base', function(A) {\r\n\tnew A.\r\n});\r\n\r\naui","type":"full"}]}

Tern response# with 19ms:
-----------------------------------
{}
-----------------------------------
Tern request#completions:
{"query":{"type":"completions","file":"docroot/js/main.js","end":44,"types":true,"docs":true,"urls":true,"origins":true,"caseInsensitive":true,"lineCharPositions":false,"expandWordForward":false,"omitObjectPrototype":false,"file":"docroot/js/main.js"}}

Tern error#completions with 26ms:
java.io.IOException: com.eclipsesource.json.ParseException: Expected ',' or '}' at 1:164673
        at tern.server.nodejs.NodejsTernHelper.makeRequest(NodejsTernHelper.java:106)
        at tern.server.nodejs.NodejsTernServer.makeRequest(NodejsTernServer.java:172)
        at tern.server.nodejs.NodejsTernServer.request(NodejsTernServer.java:237)
        at tern.resources.TernProject.request(TernProject.java:460)
        at tern.resources.TernProject.request(TernProject.java:449)
        at tern.eclipse.ide.jsdt.internal.contentassist.TernCompletionProposalComputer.computeCompletionProposals(TernCompletionProposalComputer.java:75)
        at org.eclipse.wst.jsdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:298)
        at org.eclipse.wst.jsdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:258)
        at org.eclipse.wst.jsdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:244)
        at org.eclipse.wst.jsdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:213)
        at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1861)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:573)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:570)
        at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:505)

gamerson avatar Dec 01 '14 05:12 gamerson

That's a strange error? I have tested your case and it works for me -(

I suppose that you have other JS files to parse, perhaps problem comes from those other JS files. Is your problem comes every time? Could you share your project please?

Thank's

angelozerr avatar Dec 01 '14 08:12 angelozerr

We have narrowed the problem down to a super simple example. The problem seems to come in a combination of aui and yui tern plugins added to project. disable the yui plugin and the problem goes away. @lilu1990 will send a sample project.

gamerson avatar Dec 01 '14 09:12 gamerson

Here is a sample java web project , in the tern.js file if you do code assist like" New A. alt+/" there will be nothing come out . more details please refer to this ticket https://issues.liferay.com/browse/IDE-1837 https://issues.liferay.com/secure/attachment/119164/tern-test.7z

liluCN avatar Dec 01 '14 09:12 liluCN

@lilu1990 thank's for your tern-test project. But it work's for me -(

The error trace is not the same than the tern-project (docroot/js/main.js doesn't exists? the js\tern.js doesn't contains the same JS sampel which causes the problem, etc). Is it possible to attach a project which have the same trace error please to be sure that this error trace comes from with your JS.

Which verion of tern.java do you use? The last coming from git?

Thank's

angelozerr avatar Dec 01 '14 09:12 angelozerr

The problem we only found on Windows . Mac and Linux works fine . My environment is eclipse Luna RC3 Release (4.4.0RC3) Build id: 20140604-2256 installed the latest tern from here :http://oss.opensagres.fr/tern.repository/0.7.0-SNAPSHOT/

I will update the project to the exact same one as in ticket ,please check it again , and see if you can reproduce it ,thanks .

liluCN avatar Dec 01 '14 10:12 liluCN

I'm sorry @lilu1990 I have retried and igt works well for me (I have windows)?

Are you sure that the tern-test project causes problem in your case?

angelozerr avatar Dec 03 '14 21:12 angelozerr

it is a simple java project only has a sample js file that to reproduce the problem . in a java project , create a .js file , paste some AUI script like : AUI().use('aui-base', function(A) { new A. }); then convert your project to tern project , choose both AlloyUI and YUI modules then in the function(A) when you do "new A. " + code assist , will get nothing but if you give few words for suggestion like "new A.bu" +code assist then there is Button(config), ButtonCore(config), ButtonGroup(config) in the proposals

I can reproduce the problem everytime with this tern :http://oss.opensagres.fr/tern.repository/0.7.0-SNAPSHOT/ installed on Windows Luna M6 Release (4.4.0M6) or Luna RC3 Release (4.4.0RC3)

liluCN avatar Dec 04 '14 03:12 liluCN

I'm really sorry, it works for me :

aui_works

Please retry with http://oss.opensagres.fr/tern.repository/0.8.0-SNAPSHOT/ (but I'm not sure that there is change compare to 0.7.0-SNAPSHOT)

angelozerr avatar Dec 04 '14 05:12 angelozerr

Perhaps install path has something to do with it. Lilu what is your install path? Also what is your workspace/project path? Are there any spaces or special characters?

On Thu, Dec 4, 2014 at 1:16 PM, Angelo [email protected] wrote:

I'm really sorry, it works for me :

[image: aui_works] https://cloud.githubusercontent.com/assets/1932211/5293996/fa2d6026-7b7c-11e4-958a-cf7405e597e1.png

Please retry with http://oss.opensagres.fr/tern.repository/0.8.0-SNAPSHOT/ (but I'm not sure that there is change compare to 0.7.0-SNAPSHOT)

— Reply to this email directly or view it on GitHub https://github.com/angelozerr/tern.java/issues/186#issuecomment-65539136 .

Greg Amerson Liferay Developer Tools Liferay, Inc. www.liferay.com

gamerson avatar Dec 04 '14 05:12 gamerson

If we analyze the trace :

Tern request#completions:
{"query":{"type":"completions","file":"docroot/js/main.js","end":44,"types":true,"docs":true,"urls":true,"origins":true,"caseInsensitive":true,"lineCharPositions":false,"expandWordForward":false,"omitObjectPrototype":false,"file":"docroot/js/main.js"}}

a completion is executed from the docroot/js/main.js. docroot/js/main.js doesn't exists in the zip attached (I suppose it's WebContent\WEB-INF\js\main.js). Perhaps it's just a name, but here tern project is zip doesn't match the original file name if the attached trace.

Tern error#completions with 26ms:
java.io.IOException: com.eclipsesource.json.ParseException: Expected ',' or '}' at 1:164673

Here it seems that JSON response of the completion fails. I think to know the trace of this JSON. It should be cool if you could trace the bad JSON response by modifying the Java code https://github.com/angelozerr/tern.java/blob/master/core/tern.server.nodejs/src/tern/server/nodejs/NodejsTernHelper.java#L91 (I cannot do that because I cannot reproduce the problem -()

angelozerr avatar Dec 04 '14 09:12 angelozerr

Hi Greg,

I have tried with all kinds of jdk ,1.8 ,1.7 ,1,6 , different versions of eclipse , kepler , luna, both 64 bit and 32 bit and the latest one on" eclipse.org'" install the latest tern http://oss.opensagres.fr/tern.repository/0.7.0-SNAPSHOT/ and the same problem always happens with me . There is no space/other character in my project/workspace path

my eclipse path is C:\Users\liferay\Downloads\eclipse project path C:\Users\liferay\Downloads\eclipse\ws\tern js file path C:\Users\liferay\Downloads\eclipse\ws\tern\main.js

liluCN avatar Dec 05 '14 03:12 liluCN

Lilu could you setup a dev environment and check out the latest tern.java and debug the class that Angelo mentioned previously?

On Fri, Dec 5, 2014 at 11:00 AM, Lu Li [email protected] wrote:

Hi Greg,

I have tried with all kinds of jdk ,1.8 ,1.7 ,1,6 , different versions of eclipse , kepler , luna, both 64 bit and 32 bit and the latest one on" eclipse.org'" install the latest tern http://oss.opensagres.fr/tern.repository/0.7.0-SNAPSHOT/ and the same problem always happens with me . There is no space/other character in my project/workspace path

my eclipse path is C:\Users\liferay\Downloads\eclipse project path C:\Users\liferay\Downloads\eclipse\ws\tern js file path C:\Users\liferay\Downloads\eclipse\ws\tern\main.js

— Reply to this email directly or view it on GitHub https://github.com/angelozerr/tern.java/issues/186#issuecomment-65741210 .

Greg Amerson Liferay Developer Tools Liferay, Inc. www.liferay.com

gamerson avatar Dec 05 '14 03:12 gamerson

@lilu1990 just for your info, last version now is http://oss.opensagres.fr/tern.repository/0.8.0-SNAPSHOT/ (but there are no change for aui)

Your problem is very strange? As @gamerson suggest you, it should be very cool if you can debug tern.java https://github.com/angelozerr/tern.java/blob/master/core/tern.server.nodejs/src/tern/server/nodejs/NodejsTernHelper.java#L91

Thank's!

angelozerr avatar Dec 05 '14 08:12 angelozerr

@lilu1990 in YUI tern plugin https://github.com/angelozerr/tern.java/blob/master/core/tern.core/node_modules/tern/plugin/yui.js it seems that there are some special characters like á

Could you edit this yui.js and remove special character. For instance remove the !doc from Text.AccentFold. Stope your tern server and retry the completion.

angelozerr avatar Dec 05 '14 10:12 angelozerr

Thanks Angelo, Lilu will continue to take a look at that next week. She has replicated the error in a dev workspace and so she can debug that line exactly.

On Fri, Dec 5, 2014 at 6:47 PM, Angelo [email protected] wrote:

@lilu1990 https://github.com/lilu1990 in YUI tern plugin https://github.com/angelozerr/tern.java/blob/master/core/tern.core/node_modules/tern/plugin/yui.js it seems that there are some special characters like á

Could you edit this yui.js and remove special character. For instance remove the !doc from Text.AccentFold. Stope your tern server and retry the completion.

— Reply to this email directly or view it on GitHub https://github.com/angelozerr/tern.java/issues/186#issuecomment-65773836 .

Greg Amerson Liferay Developer Tools Liferay, Inc. www.liferay.com

gamerson avatar Dec 05 '14 13:12 gamerson

Thank's @gamerson @lilu1990 for your help.

This error is very strange, the node.js tern server returns always JSON result and in this case, the server returns JSON but on the client side (mimimal JSON with Java) it seems that it's not a valid JSON. It work's for me but for @lilu1990 I suspect that it's an encoding problem (again encoding problem...).

I don't know if we should do something to display the stream result when JSON is not valid. To do that we must use ByteArrayInputStream or re-execute the query when ParseException is done. What do you thaink about that @gamerson (don't know if I have well explained?)

angelozerr avatar Dec 05 '14 23:12 angelozerr

@lilu1990 have you again the problem with new plugin of YUI/AUI?

angelozerr avatar Jan 24 '15 16:01 angelozerr

aui only aui2 0 yui3 0 aui 1 5x yui3 0

@angelozerr I still have some problem with the code assist when there is no yui module for project , or the situation when it is a combine of aui 1.5x +yui3 , it only shows yui3 content

liluCN avatar Jan 26 '15 07:01 liluCN

@lilu1990 it's a new problem, could you create an issue with this problem at https://github.com/angelozerr/tern-aui2.0.x/issues thanks!

angelozerr avatar Jan 26 '15 08:01 angelozerr