Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Uncaught SyntaxError: Unexpected token C in JSON at position 0 #44

Open
sumyapp opened this issue Sep 12, 2017 · 11 comments
Open

Uncaught SyntaxError: Unexpected token C in JSON at position 0 #44

sumyapp opened this issue Sep 12, 2017 · 11 comments

Comments

@sumyapp
Copy link

sumyapp commented Sep 12, 2017

[Enter steps to reproduce:]

  1. Run auto-correct current file
  2. this error happen. every file, this error happens.

Atom: 1.19.7 x64
Electron: 1.6.9
OS: Mac OS X 10.12.6
Thrown From: rubocop-auto-correct package 1.5.1

Stack Trace

Uncaught SyntaxError: Unexpected token C in JSON at position 0

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

SyntaxError: Unexpected token C in JSON at position 0
    at JSON.parse (<anonymous>)
    at /packages/rubocop-auto-correct/lib/rubocop-auto-correct.coffee:129:27
    at Socket.<anonymous> (/Applications/Atom.app/Contents/Resources/app/src/buffered-process.js:212:17)
    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:551:20)

Commands

  3x -1:07.5.0 core:move-up (input.hidden-input)
     -1:06.8.0 core:select-down (input.hidden-input)
     -1:06.6.0 core:backspace (input.hidden-input)
  2x -1:06.4.0 core:move-up (input.hidden-input)
     -1:05.8.0 core:select-up (input.hidden-input)
     -1:05.2.0 core:backspace (input.hidden-input)
  3x -1:04.9.0 core:move-up (input.hidden-input)
     -1:04.1.0 core:select-down (input.hidden-input)
     -1:03.7.0 core:select-left (input.hidden-input)
  2x -1:03.3.0 core:backspace (input.hidden-input)
     -1:02.6.0 core:move-right (input.hidden-input)
  4x -1:02.3.0 core:move-down (input.hidden-input)
     -1:01.5.0 core:save (input.hidden-input)
     -0:56.5.0 core:move-down (input.hidden-input)
     -0:56.1.0 core:backspace (input.hidden-input)
     -0:55.2.0 core:save (input.hidden-input)

Non-Core Packages

atom-beautify 0.30.5 
busy-signal 1.4.3 
color-picker 2.2.5 
file-icons 2.1.11 
git-plus 7.9.3 
intentions 1.1.5 
language-javascript-jsx 0.3.7 
linter 2.0.0 
linter-rubocop 2.1.1 
linter-ui-default 1.6.8 
markdown-preview-plus 2.4.10 
pretty-json 1.6.4 
rubocop-auto-correct 1.5.1 
ruby-slim 0.2.0 

Version

$ bundle exec rubocop -v
0.49.1
@tomoya
Copy link
Owner

tomoya commented Sep 16, 2017

Hi @sumyapp,

How many times did this error occur? I want to know that this error has occurred every time or sometimes. And let me know where rubocop is installed (e.g. run where rubocop in terminal).

Thank you

@sumyapp
Copy link
Author

sumyapp commented Sep 17, 2017

Thanks for the reply. Every time.
rubocop installed here.

myname$ which rubocop
/Users/myname/.rbenv/shims/rubocop

And, this is my configure. linter-rubocop is run properly.

  "linter-rubocop":
    command: "/Users/myname/.rbenv/shims/bundle exec rubocop"
  "rubocop-auto-correct":
    autoRun: true
    correctFile: true
    rubocopCommandPath: "/Users/myname/.rbenv/shims/bundle exec rubocop"

@tomoya
Copy link
Owner

tomoya commented Sep 18, 2017

@sumyapp Thank you for your investigation.

Quick fix is you change rubocopCommandPath configuration to /Users/myname/.rbenv/shims/rubocop.
Because the path of the rubocop-auto-correct command cannot contain arguments.

If you want to use bundle exec strongly, I will be able to apply it. Do you want?

@sumyapp
Copy link
Author

sumyapp commented Sep 19, 2017

Thank you for telling me.
I tried that. Unfortunately, it did not work in my environment. My environment may be strange. Sorry to trouble you.

The output errors are as follows.

rbenv: rubocop: command not found
The `rubocop 'command exists in these Ruby versions:
2.3.1

I am using multiple versions of Ruby. Also, I use multiple versions of RuboCop.

@tomoya
Copy link
Owner

tomoya commented Sep 26, 2017

I got it.

If you launch Atom on terminal (this meaning is Atom knows PATH environment), You do not need to set rubocopCommandPath. I also use multiple ruby environments in rbenv. However, rbenv can automatically resolve path of rubocop command.

@sumyapp
Copy link
Author

sumyapp commented Oct 2, 2017

I can not make enough time to verify, so I give up once. I am very sorry.

my new config.cson

  "linter-rubocop":
    command: "rubocop"
  "rubocop-auto-correct":
    autoRun: false
    correctFile: true

launch command

$ atom .
# Open ruby file include rubocop warning codes
# linter-rubocop suggest warning
# rubocop-auto-correct appear error(attach the image)

screen shot 2017-10-02 at 18 33 32

rubocop is installed correctly.

$ bundle install | grep rubocop
Using rubocop 0.49.1
Using rubocop-checkstyle_formatter 0.4.0
Using rubocop-rspec 1.15.1
$ rubocop -v
0.49.1
$ which rubocop
/Users/myname/.rbenv/shims/rubocop

@tomoya
Copy link
Owner

tomoya commented Oct 3, 2017

OMG! Your rubocop installed path is same with me.

$ where rubocop
/Users/tomoya/.rbenv/shims/rubocop

Could you check process.env.PATH value on Atom's DevTools console?

View > Developer > Toggle Developer Tools (Alt + Cmd + i)

In my case, like this.

image

@sumyapp
Copy link
Author

sumyapp commented Oct 4, 2017

Is this it?

> process.env.PATH
< "/usr/local/sbin:/usr/local/opt/sqlite/bin:/usr/local/opt/imagemagick@6/bin:/usr/local/opt/openssl/bin:/Users/koichiro/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

@tomoya
Copy link
Owner

tomoya commented Oct 6, 2017

Hi @sumyapp, Thank you for your response.

I believe that the cause is rbenv. process.env.PATH includes /Users/koichiro/.rbenv/shims. So, your environment variable is correct.

But your error messages are rbenv: rubocop: command not found and The rubocop command existsin these ruby version. Thus your calling ruby version cannot find rubocop command.

I guess that your environment has several ruby version, and your repository ruby version was not installed rubocop command.

In other words, your repository has .ruby-version file and selected other ruby versions, I guess.

Could you check your ruby version in your repository? Like a below,

$ where ruby
/Users/tomoya/.rbenv/shims/ruby
/usr/bin/ruby
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]

Thank you,

@sumyapp
Copy link
Author

sumyapp commented Oct 9, 2017

Sorry, I think, RuboCop is installed correctly.
Is there a way to check ruby version running rubocop-auto-correct?

$ which ruby
/Users/koichiro/.rbenv/shims/ruby
$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
$ bundle list | grep rubocop
  * rubocop (0.49.1)
  * rubocop-checkstyle_formatter (0.4.0)
  * rubocop-rspec (1.15.1)
$ rubocop -v
0.49.1
$ rbenv which rubocop
/Users/koichiro/.rbenv/versions/2.4.2/bin/rubocop

@tom-lord
Copy link

tom-lord commented Jun 15, 2018

I'm seeing this same issue.

Using the default rubocop command path (just rubocop) works OK, but uses the latest installed rubocop version for my current ruby version (currently 0.57.2, but this project uses 0.52.1) - therefore I'm seeing a bunch of errors about deprecated cops etc.

Using a custom rubocop command path (bundle exec rubocop, or /Users/myname/.rbenv/shims/rubocop, or whatever) results in the error described above. I'm not sure how to diagnose the root cause.

As a temporary workaround, just to get it working, I'm manually setting the rubocop path to the one needed for this project:

/Users/tomlord/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/rubocop-0.52.1/bin/rubocop

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants