wysiib / linter-languagetool

Integration of Languagetool into the Atom text editor.
MIT License
17 stars 5 forks source link

Uncaught SyntaxError: Unexpected token E in JSON at position 0 #16

Closed jeanrjc closed 6 years ago

jeanrjc commented 6 years ago

Hi, I got the following error when installing your package:

Step to reproduce:

  1. Install the package
  2. Start writting some text in a .tex file. The error does not occur in a .txt file.

Atom: 1.19.7 x64 Electron: 1.6.9 OS: Mac OS X 10.11.5 Thrown From: linter-languagetool package 0.5.0

Stack Trace

Uncaught SyntaxError: Unexpected token E in JSON at position 0

At file:///Applications/Atom.app/Contents/Resources/app/static/index.html:1

SyntaxError: Unexpected token E in JSON at position 0
    at JSON.parse (<anonymous>)
    at /packages/linter-languagetool/lib/linter-provider.coffee:103:29)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Commands

     -1:35.5.0 tree-view:show (atom-workspace.workspace.scrollbars-visible-when-scrolling)
  2x -1:01.3.0 linter-ui-default:toggle-panel (atom-workspace.workspace.scrollbars-visible-when-scrolling.theme-one-light-syntax.theme-one-light-ui)
     -0:42.3.0 core:backspace (input.hidden-input)
     -0:40.1.0 core:confirm (input.hidden-input)

Non-Core Packages

atom-beautify 0.30.5 
autocomplete-bibtex 0.7.0 
autocomplete-python 1.10.2 
busy-signal 1.4.3 
color-picker 2.2.5 
dictionary 0.5.0 
file-icons 2.1.11 
git-blame 1.2.2 
git-plus 7.9.3 
git-time-machine 1.5.9 
hyperclick 0.1.3 
indent-guide-improved 1.4.12 
intentions 1.1.5 
language-latex 1.1.1 
language-restructuredtext 1.1.0 
languagetool 0.1.1 
latex-autocomplete 1.0.0 
latex-completions 0.3.3 
latex-plus 0.9.1 
latexer 0.3.0 
latextools 0.8.5 
linter 2.2.0 
linter-chktex 1.3.1 
linter-just-say-no 0.7.3 
linter-languagetool 0.5.0 
linter-ui-default 1.6.8 
linter-write-good 0.9.0 
minimap 4.29.6 
pdf-view 0.59.0 
pigments 0.39.1 
project-manager 3.3.5 
rst-preview 1.3.1 
rst-preview-pandoc 0.1.12 
wordcount 2.10.4 
Zen 0.18.0 
jeanrjc commented 6 years ago

The error might come from the fact that my .tex file is too big (~50k characters) for the languagestool server because it works on smaller files. I'm not sure though. If this is the case, a more verbose error message could be convenient.

jeanrjc commented 6 years ago

Well, it also occurs on smaller files, but at one point, the bug disappears and languagetool works again, but the bug can reappear randomly.

wysiib commented 6 years ago

This might be caused by the startup time of the language tool server. Maybe it is not accepting requests immediately and thus the error disappears as soon as startup is completed. I'll have to check the behaviour on larger files as well.

Furthermore, the token "E" might be the start of an error message. I'll see if I can output the full error message instead of throwing the exception.

wysiib commented 6 years ago

I just released version 0.5.1. Hopefully, it will show you the answer received from the LanguageTool server for further debugging.

jeanrjc commented 6 years ago

I have indeed a warning (which disappear a bit too rapidly) with the appropriate error message:

image

The stack Trace of the new error is:

TypeError: Cannot read property 'matches' of undefined
    at IncomingMessage.<anonymous> (/Users/xxxx/.atom/packages/linter-languagetool/lib/linter-provider.coffee:108:32)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I did not have any errors with smaller files (yet?).

Maybe it could be nice to send the 20k char to the server that are around the cursor, if the file contains more than 20k chars or something similar to this.

Thanks

wysiib commented 6 years ago

Are you using the public LanguageTool Server or did you set up a server on your machine (just need too download a jar file). I believe the limit only applies for the public server. That is, the proper solution of your problem would be to run language tool on your own device.

Of course we should fix the error message.

jeanrjc commented 6 years ago

You're right. I used the public server. I tried the local server the last time but it did not work, but now it works, so it's good. I updated to version 0.5.2 and the error message disappeared so it's good.

Just the warning message disappears a bit too quickly, so you barely have time to realize what it is, especially if you don't expect it. If you can, adding a message advising to switch to a local server as a solution might be better than recommending shortening the text.

Thank you very much for the rapid fix and solution!

wysiib commented 6 years ago

I'll try to keep the warning message open a little bit longer. However, I currently think that it is controlled by Atom itself and we can not really influence it.

An improved error message however is a nice suggestion!