Skip to content

Uncaught SyntaxError: Unexpected token m in JSON at position 9 #1216

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

Closed
ZuBB opened this issue Mar 20, 2017 · 9 comments · Fixed by #1243
Closed

Uncaught SyntaxError: Unexpected token m in JSON at position 9 #1216

ZuBB opened this issue Mar 20, 2017 · 9 comments · Fixed by #1243
Assignees

Comments

@ZuBB
Copy link

ZuBB commented Mar 20, 2017

[Enter steps to reproduce:]

  1. ...
  2. ...

Atom: 1.15.0 x64
Electron: 1.3.13
OS: Mac OS X 10.12.3
Thrown From: atom-typescript package 11.0.1

Stack Trace

Uncaught SyntaxError: Unexpected token m in JSON at position 9

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

SyntaxError: Unexpected token m in JSON at position 9
    at Object.parse (native)
    at MessageStream._transform (/packages/atom-typescript/dist/client/client.js:198:28)
    at MessageStream.Transform._read (_stream_transform.js:167:10)
    at MessageStream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at MessageStream.Writable.write (_stream_writable.js:220:11)
    at LineStream.ondata (_stream_readable.js:555:20)
    at emitOne (events.js:96:13)
    at LineStream.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at LineStream.Readable.push (_stream_readable.js:134:10)
    at LineStream.Transform.push (_stream_transform.js:128:32)
    at LineStream._pushBuffer (/packages/atom-typescript/node_modules/byline/lib/byline.js:126:17)
    at LineStream._transform (/packages/atom-typescript/node_modules/byline/lib/byline.js:117:8)
    at LineStream.Transform._read (_stream_transform.js:167:10)
    at LineStream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at LineStream.Writable.write (_stream_writable.js:220:11)
    at Socket.ondata (_stream_readable.js:555:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at Pipe.onread (net.js:543:20)

Commands

     -0:42.7.0 vim-mode-plus:move-to-middle-of-screen (input.hidden-input)
     -0:41.5.0 vim-mode-plus:move-up (input.hidden-input)
  4x -0:41.2.0 vim-mode-plus:move-down (input.hidden-input)
     -0:39.7.0 vim-mode-plus:scroll-half-screen-down (input.hidden-input)
  5x -0:35.3.0 vim-mode-plus:move-down (input.hidden-input)
  6x -0:34.1.0 vim-mode-plus:move-to-next-word (input.hidden-input)
     -0:32.7.0 vim-mode-plus:activate-characterwise-visual-mode (input.hidden-input)
     -0:32.7.0 vim-mode-plus:move-to-end-of-word (input.hidden-input)
     -0:32.5.0 vim-mode-plus:move-right (input.hidden-input)
     -0:32 vim-mode-plus:delete (input.hidden-input)
  2x -0:26.6.0 core:save (input.hidden-input)
     -0:15.2.0 core:close (input.hidden-input)
     -0:09.6.0 fuzzy-finder:toggle-file-finder (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-one-dark-ui)
     -0:09.1.0 core:paste (input.hidden-input)
     -0:08.8.0 core:confirm (input.hidden-input)
  3x -0:07.8.0 vim-mode-plus:move-down (input.hidden-input)

Non-Core Packages

atom-beautify 0.29.17 
atom-shortcuts 0.0.2 
atom-typescript 11.0.1 
atom-vim-keymap 1.0.1 
busy-signal 1.3.0 
editor-stats 0.17.0 
editorconfig 2.2.2 
ex-mode 0.14.0 
git-control 0.8.2 
git-plus 7.3.3 
goto-definition 1.2.1 
intentions 1.1.2 
linter 2.1.0 
linter-ui-default 1.2.1 
open-recent 5.0.0 
project-manager 3.3.3 
svg-preview 0.11.0 
sync-settings 0.8.1 
vim-mode-plus 0.84.1 
vim-mode-plus-ex-mode 0.9.0 
webbox-color 0.5.9 
@ZuBB
Copy link
Author

ZuBB commented Mar 20, 2017

@guncha this same error I have reported here #1166 (comment)

I understand this is indeed bad bugreport since I do not have exact STR. but could you please add additional check to actually prevent it?

@guncha
Copy link
Contributor

guncha commented Mar 20, 2017

It indicates a deeper problem with the tsserver protocol parser. I took the quick and easy approach and piped it all through a byline stream and just assume that every third line is the JSON message. If the count gets out of sync somehow, it'll simply stop working altogether. Did you run any commands when this happened? Does it happen right after you start the editor? Open a new tab? I'll look into it, but a way to reproduce would make that much easier.

@guncha guncha self-assigned this Mar 20, 2017
@guncha
Copy link
Contributor

guncha commented Mar 20, 2017

@ZuBB also, what's your Typescript version for the project where this happens?

@ZuBB
Copy link
Author

ZuBB commented Mar 20, 2017

@ZuBB also, what's your Typescript version for the project where this happens?

2.1.6

@ZuBB
Copy link
Author

ZuBB commented Mar 20, 2017

Did you run any commands when this happened?

just to omit any confusion: what do you mean under "run any commands"?

Does it happen right after you start the editor?

definitely not

Open a new tab?

quite possible, but I am not totally sure. I remember that I has lots of tabs opened and I walk through them and do incremental search (vim's N)

I will try to recall what causes next time i get this. btw I got this today couple of times

@ZuBB
Copy link
Author

ZuBB commented Mar 22, 2017

got one more time it today. last tree actions was next:

  • search with n/N
  • switch to browser
  • switch back to atom

and voila - toast with error appeared

@guncha
Copy link
Contributor

guncha commented Mar 22, 2017

Thanks. When you switch tabs, the plugin will trigger error checking for that file that will in turn generate some events from tsserver. The searching will move the cursor that will send occurences command to tsserver to highlight the symbols in the current file. I guess it could be either of those, but I still can't reproduce.

Only thing I can think of would be to add some logging to the tsserver protocol to see what's going on. There's a MessageStream class in client.ts that reads the lines from the server, so if you change the _transform method to log the lines, it should gives us a clue on what's going on:

/** Helper to parse the tsserver output stream to a message stream  */
class MessageStream extends Transform {
  lineCount = 1

  constructor() {
    super({objectMode: true})
  }

  _transform(line: string, encoding: string, callback: Function) {
    console.log(this.lineCount + ":" + line) // add this

    if (this.lineCount % 2 === 0) {
      this.push(JSON.parse(line))
    }

    this.lineCount += 1

    callback(null)
  }
}

@ZuBB
Copy link
Author

ZuBB commented Mar 27, 2017

I just recall that we added some debug lines :)

I am adding two screens of console. hope it will help us to move further on this (or this) issue(s)

screen shot 2017-03-27 at 12 47 50

screen shot 2017-03-27 at 12 47 53

@guncha
Copy link
Contributor

guncha commented Mar 27, 2017

Okay, I see, the tsserver process is crashing with an OOM error and prints something on stdout that is not a protocol message. The solution here is to gracefully handle the server crashing as well as printing arbitrary lines on stdout. I have some ideas for this, hang tight!

@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants