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

Rubocop doesn't show problems due to segfault #1467

Closed
andypike opened this issue Jul 8, 2015 · 9 comments
Closed

Rubocop doesn't show problems due to segfault #1467

andypike opened this issue Jul 8, 2015 · 9 comments

Comments

@andypike
Copy link

andypike commented Jul 8, 2015

Hi,

Firstly I'm a bit of a Vim newbie so I might have done something wrong but I can't get rubocop to display issues in Vim even though it runs fine outside in the terminal. I've tried to get as much information as I can and I can see a segfault in the Syntastic debug log.

I am editing this project/branch in Vim: https://github.com/loyaltylion/nala/tree/syntax_errors and in particular the file: https://github.com/loyaltylion/nala/blob/syntax_errors/lib/nala/publisher.rb which has a syntax error.

Here is some information from my terminal (I use rvm):

$ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

$ rubocop --version
0.32.1

This is my .vimrc config (snipped):

let g:syntastic_ruby_checkers = ['rubocop']
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_debug=3

With debug set to 3, I see this output when I open publisher.rb in vim (snipped):

"~/code/loyalty_lion/nala/lib/nala/publisher.rb" 33L, 507C
syntastic: 7.049501: &shell = '/bin/zsh', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shellslash = 0, &shelltemp = 1, &shellxquote = '', &shellxescape = ''
syntastic: 7.049652: UpdateErrors (auto): default checkers
syntastic: 7.049904: CacheErrors: default checkers
syntastic: 7.050489: g:syntastic_aggregate_errors = 0
syntastic: 7.050619: getcwd() = '/Users/andypike/code/loyalty_lion/nala'
Command terminated
syntastic: 7.834535: CacheErrors: Invoking checker: ruby/rubocop
syntastic: 7.835136: SyntasticMake: called with options: {'subtype': 'Style', 'errorformat': '%f:%l:%c: %t: %m', 'makeprg': 'rubocop --format emacs lib/nala/publisher.rb'}
Command terminated
syntastic: 8.591052: checker output: ['/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext/parser.bundle: [BUG] Segmentation fault', 'ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]', '', '--
Crash Report log information --------------------------------------------', '   See Crash Report log file under the one of following:', '     * ~/Library/Logs/CrashReporter', '     * /Library/Logs/CrashReporter', '     * ~/Librar
y/Logs/DiagnosticReports', '     * /Library/Logs/DiagnosticReports', '   the more detail of.', '', '-- Control frame information -----------------------------------------------', 'c:0024 p:-17565820487988 s:0110 e:000109 TOP    [
FINISH]', 'c:0023 p:---- s:0108 e:000107 CFUNC  :require', 'c:0022 p:0115 s:0104 e:000103 METHOD /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55', 'c:0021 p:0009 s:
0094 e:000093 CLASS  /Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext.rb:13', 'c:0020 p:0011 s:0092 e:000091 CLASS  /Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext.rb:12', 'c:0019 p:0057 s:0090
e:000089 TOP    /Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext.rb:9 [FINISH]', 'c:0018 p:---- s:0088 e:000087 CFUNC  :require', 'c:0017 p:0115 s:0084 e:000083 METHOD /System/Library/Frameworks/Ruby.framework/Ve
rsions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55', 'c:0016 p:0019 s:0074 e:000073 CLASS  /Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json.rb:58', 'c:0015 p:0017 s:0072 e:000071 TOP    /Users/andyp
ike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json.rb:54 [FINISH]', 'c:0014 p:---- s:0070 e:000069 CFUNC  :require', 'c:0013 p:0115 s:0066 e:000065 METHOD /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/r
ubygems/core_ext/kernel_require.rb:55', 'c:0012 p:0007 s:0056 e:000055 TOP    /Users/andypike/.rvm/gems/ruby-2.2.2/gems/rubocop-0.32.1/lib/rubocop/formatter/json_formatter.rb:3 [FINISH]', 'c:0011 p:---- s:0054 e:000053 CFUNC  :re
quire', 'c:0010 p:0115 s:0050 e:000049 METHOD /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55', 'c:0009 p:2380 s:0040 e:000039 TOP    /Users/andypike/.rvm/gems/ruby
-2.2.2/gems/rubocop-0.32.1/lib/rubocop.rb:311 [FINISH]', 'c:0008 p:---- s:0038 e:000037 CFUNC  :require', 'c:0007 p:0115 s:0034 e:000033 METHOD /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/co
re_ext/kernel_require.rb:55', 'c:0006 p:0038 s:0024 e:000023 TOP    /Users/andypike/.rvm/gems/ruby-2.2.2/gems/rubocop-0.32.1/bin/rubocop:6 [FINISH]', 'c:0005 p:---- s:0019 e:000018 CFUNC  :load', 'c:0004 p:0134 s:0015 E:0007b8 EV
AL   /Users/andypike/.rvm/gems/ruby-2.2.2/bin/rubocop:23 [FINISH]', 'c:0003 p:---- s:0011 e:000010 CFUNC  :eval', 'c:0002 p:0118 s:0005 E:0003f0 EVAL   /Users/andypike/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15 [FINISH]',
'c:0001 p:0000 s:0002 E:0007f8 TOP    [FINISH]', '', '/Users/andypike/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>''', '/Users/andypike/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval''', '/Users/andypi
ke/.rvm/gems/ruby-2.2.2/bin/rubocop:23:in `<main>''', '/Users/andypike/.rvm/gems/ruby-2.2.2/bin/rubocop:23:in `load''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/rubocop-0.32.1/bin/rubocop:6:in `<top (required)>''', '/System/Lib
rary/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:
55:in `require''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/rubocop-0.32.1/lib/rubocop.rb:311:in `<top (required)>''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.
rb:55:in `require''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/rubocop-0.32.1/lib/rubocop/formatt
er/json_formatter.rb:3:in `<top (required)>''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/System/Library/Frameworks/Ruby.framework/Versions
/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json.rb:54:in `<top (required)>''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/li
b/json.rb:58:in `<module:JSON>''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/
ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext.rb:9:in `<top (required)>''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext
.rb:12:in `<module:JSON>''', '/Users/andypike/.rvm/gems/ruby-2.2.2/gems/json-1.8.2/lib/json/ext.rb:13:in `<module:Ext>''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_requir
e.rb:55:in `require''', '/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require''', '', '-- C level backtrace information -------------------------------------
------', '',

...

If I run (what I assume is the correct command from the output) in my terminal, rubocop seems to work correctly:

$ rubocop --format emacs lib/nala/publisher.rb
/Users/andypike/code/loyalty_lion/nala/lib/nala/publisher.rb:33:1: E: unexpected token kEND

So, I may well have done something odd and I'm happy to give you further information. What else can I provide that would help? I also tried with Ruby 2.1.5 and an older version of rubocop (0.28.0) as well as version 0.32.1 which had the same result.

Oh and here is my vim info (when using Ruby 2.1.5):

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul  6 2015 23:26:40)
MacOS X (unix) version
Included patches: 1-712
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         -gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib  -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -framework Python   -lruby.2.1.0 -lobjc -L/Users/andypike/.rvm/rubies/ruby-2.1.5/lib

Thanks in advance.

Andy

💖

@lcd047
Copy link
Collaborator

lcd047 commented Jul 9, 2015

Does this help?

@andypike
Copy link
Author

andypike commented Jul 9, 2015

Hi,

Thanks for the fast reply! I added the following to my .vimrc file (but I'm not using MacVim, just normal Vim installed through homebrew with brew install vim):

let g:syntastic_shell = "/bin/sh"

Now I see the error checker ruby/rubocop: can't parse version string (abnormal termination?), here is the full debug:

"~/code/loyalty_lion/nala/lib/nala/publisher.rb" 33L, 507C
syntastic: 4.302558: &shell = '/bin/zsh', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shellslash = 0, &shelltemp = 1, &shellxquote = '', &shellxescape = ''
syntastic: 4.302707: UpdateErrors (auto): default checkers
syntastic: 4.302978: CacheErrors: default checkers
syntastic: 4.303495: g:syntastic_aggregate_errors = 0
syntastic: 4.303693: getcwd() = '/Users/andypike/code/loyalty_lion/nala'
syntastic: error: checker ruby/rubocop: can't parse version string (abnormal termination?)
syntastic: 5.438832: CacheErrors: Checker ruby/rubocop is not available
syntastic: 5.439003: CacheErrors: no checkers available for ruby
syntastic: 5.439073: aggregated: {'_sorted': 0, '_name': '', '_owner': 1, '_columns': 1, '_rawLoclist': []}
Press ENTER or type command to continue

If I run :SyntasticInfo I get the following (rubocop not listed):

Syntastic version: 3.6.0-117 (Vim 704, Darwin)
Info for filetype: ruby
Global mode: active
Filetype ruby is active
The current file will be checked automatically
Available checkers: mri reek
Currently enabled checkers: -

If I then try :echo system('rubocop --version'), I get the following segfault again:

Command terminated
/Users/andypike/.rvm/gems/ruby-2.1.5/gems/json-1.8.2/lib/json/ext/parser.bundle: [BUG] Segmentation fault
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

I notice that ruby 2.0.0p481 is listed (which isn't installed via rvm so must be the system ruby) so I guess the path is not correct or something?

In my terminal the path is:

$ echo $PATH
/Users/andypike/.rvm/gems/ruby-2.1.5/bin:/Users/andypike/.rvm/gems/ruby-2.1.5@global/bin:/Users/andypike/.rvm/rubies/ruby-2.1.5/bin:/usr/local/heroku/bin:/usr/local/bin:/Users/andypike/.nvm/versions/io.js/v1.7.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/andypike/.rvm/bin

In Vim, I tried to see the path:

:echo system('$PATH')
zsh:1: no such file or directory: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/andypike/.rvm/gems/ruby-2.1.5/bin:/Users/andypike/.rvm/gems/ruby-2.1.5@global/bin:/Users/andypike/.rvm/rubies/ruby-2.1.5/bin:/usr/local/heroku/bi
n:/Users/andypike/.nvm/versions/io.js/v1.7.1/bin:/Users/andypike/.rvm/bin

From this it looks like within Vim the rvm paths are listed after the system paths so I'm assuming it's using the wrong ruby?

If I try to see which ruby is being used in Vim I get this (as expected):

:echo system('which ruby')
/usr/bin/ruby

As a test, I renamed the system ruby (temporality) to something else and tried again, this time I get an rvm path in Vim:

:echo system('which ruby')
/Users/andypike/.rvm/rubies/ruby-2.1.5/bin/ruby

I tried opening the ruby file again in Vim, but got the same error above:

"~/code/loyalty_lion/nala/lib/nala/publisher.rb" 33L, 507C
syntastic: 5.343442: &shell = '/bin/zsh', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir
= '>%s 2>&1', &shellslash = 0, &shelltemp = 1, &shellxquote = '', &shellxescape = ''
syntastic: 5.343597: UpdateErrors (auto): default checkers
syntastic: 5.343814: CacheErrors: default checkers
syntastic: 5.344386: g:syntastic_aggregate_errors = 0
syntastic: 5.344565: getcwd() = '/Users/andypike/code/loyalty_lion/nala'
syntastic: error: checker ruby/rubocop: can't parse version string (abnormal termination?)
syntastic: 6.294699: CacheErrors: Checker ruby/rubocop is not available
syntastic: 6.294863: CacheErrors: no checkers available for ruby
syntastic: 6.294935: aggregated: {'_sorted': 0, '_name': '', '_owner': 1, '_columns': 1, '_rawLoclist': []}

At this point I'm not really sure what I'm doing, sorry to be a pain. Any tips I can tryout?

Thanks again

Andy

❤️ 💙 💖

@lcd047
Copy link
Collaborator

lcd047 commented Jul 9, 2015

As you probably have already guessed, all this is between your shell, ruby, rubocop, and vim. It has nothing to do with syntastic. It's probably better to fix the problems, even though syntastic does offer some workarounds.

let g:syntastic_shell = "/bin/sh"

It's probably a better idea to run things under a shell that you did configure. That is, try to get the environment fixed in zsh first.

If I then try :echo system('rubocop --version'), I get the following segfault again

Yup, that's what you need to fix. However, if you go the route of changing g:syntastic_shell you need to run something like this instead, because that's what syntastic calls:

:echo syntastic#util#system('rubocop --version')

Fixing rvm will probably fix the segfault.

:echo system('$PATH')

No, that doesn't make any sense. The echo here is Vim's echo, you also want the shell's one:

:echo system('echo $PATH')

or

:echo syntastic#util#system('echo $PATH')

:echo system('which ruby')

This is not really relevant, since the rubocop script starts with this:

#!/usr/bin/ruby

At this point I'm not really sure what I'm doing, sorry to be a pain. Any tips I can tryout?

Your MacVim, ruboop, and zsh are all conspiring to make this a pain in the rear (and, sadly, I'm only half joking). I'm not using any of those so the best I can do is point you to what other people claimed to have worked for them in the past. Sorry about that. Once you get either system('rubocop --version') or syntastic#util#system('rubocop --version') to produce a version string without segfaults, I can help you with the parts relevant to syntastic...

@andypike
Copy link
Author

andypike commented Jul 9, 2015

OK, no problem. Thanks for the feedback and I agree this isn't a syntastic issue but a setup one of my environment. I'll keep trying and will see what I can do.

Thanks again 💖

@andypike
Copy link
Author

andypike commented Jul 9, 2015

For anyone else that might see this, I am currently running ruby 2.1.5 (via rvm). When I run this command in Vim:

:echo syntastic#util#system('rubocop --version')

I get the following output, so I guess the warning output from rubocop is messing things up when it comes to parsing the version number?:

warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.6-compliant syntax, but you are running 2.1.5.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
0.32.1

So I installed ruby 2.1.6 with rvm, switched to it and installed rubocop for it. Now it's working fine. I removed the let g:syntastic_shell = "/bin/sh" from my .vimrc file and it still works.

I'm not sure if syntastic should do something different if the reported version from rubocop is malformed, but that was the issue as far as I can see. I hope this is useful.

@lcd047
Copy link
Collaborator

lcd047 commented Jul 9, 2015

Just make sure nothing is segfaulting under your feet.

warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.6-compliant syntax, but you are running 2.1.5.

That's a different issue (see this if you're curioous about the chain of blame). It's more or less addressed in the wiki. Sadly, rubocop is too useful to remove from syntastic. :)

@lcd047 lcd047 closed this as completed Jul 9, 2015
@andypike
Copy link
Author

andypike commented Jul 9, 2015

Yeah, I saw that but when run from the terminal rubocop --version just reports the version which is very odd that it's different in Vim. The key for me was running :echo syntastic#util#system('rubocop --version') in Vim which made it easy to fix so thank you for that. Maybe if that command was added to that wiki page it might help others?

Anyway, thank you so much for your help. I'm loving using Syntastic already!

💖

@lcd047
Copy link
Collaborator

lcd047 commented Jul 9, 2015

In terminal you didn't have that problem because rvm worked. Should you have gotten it to also work in vim, you wouldn't have run into segfaults and you wouldn't have needed g:syntastic_shell. The root of the problem is the interaction between MacVim and zsh. Changing the shell is a hack that tries to avoid that interaction and get rvm to run, it isn't particularly related to rubocop. Apparently it doesn't work either, so I'll take it out of the manual.

On the other hand, the other problem was rubocop --version spamming stderr with warnings, and syntastic, rubocop, and parser not wanting to take responsibility for those messages. Well, that's really lame, but it can be worked around.

@vrybas
Copy link

vrybas commented Jan 14, 2016

So this is my workaround for now:

/Users/me/nowarnrubocop.sh

exec ruby -W0 -S rubocop "$@"

/Users/me/.vimrc

let g:syntastic_ruby_rubocop_exec = '/Users/me/nowarnrubocop.sh'
let g:syntastic_ruby_checkers = ['rubocop']

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

No branches or pull requests

3 participants