Vimjas / vint

Fast and Highly Extensible Vim script Language Lint implemented in Python.
MIT License
703 stars 33 forks source link

Syntastic: `unrecognized error format (crashed checker?)`? #198

Open rlue opened 7 years ago

rlue commented 7 years ago

I'm getting an error when I run :SyntasticCheck on VimL files. I have vim configured with only the options suggested for new users in Syntastic's README:

let g:syntastic_vim_checkers = ['vint']

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

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

Here's the output for the Syntastic debug log:

syntastic: warning: checker vim/vint: unrecognized error format (crashed checker?)
syntastic: 255.519186: g:syntastic_version = '3.8.0-3 (Vim 800, Darwin, GUI)'
syntastic: 255.519360: &shell = '/bin/bash', &shellcmdflag = '-c', 
  &shellpipe = '2>&1 | tee', 
  &shellquote = '', 
  &shellredir = '>%s 2>&1', 
  &shelltemp = 1, 
  &shellxquote = '', 
  &autochdir = 0, 
  &shellxescape = ''
syntastic: 255.519927: UpdateErrors: vint
syntastic: 255.520186: CacheErrors: vint
syntastic: 255.520800: g:syntastic_aggregate_errors = 0
syntastic: 255.520984: getcwd() = '/Users/rlue'
syntastic: 255.521474: CacheErrors: Invoking checker: vim/vint
syntastic: 255.522067: SyntasticMake: called with options: 
  {'preprocess': 'vint', 
   'errorformat': '%f:%l:%c:%t: %m', 
   'makeprg': 'vint /Users/rlue/.vim/config/mappings.vim --json', 
   'returns': [0, 1]}
syntastic: 255.847839: system: command run in 0.325377s
syntastic: 255.848224: checker output: 
  ['Traceback (most recent call last):', 
   '  File "/usr/local/bin/vint", line 11, in <module>', 
   '    sys.exit(main())', 
   '  File "/usr/local/lib/python2.7/site-packages/vint/__init__.py", line 11, in main', 
   '    init_cli()', 
   '  File "/usr/local/lib/python2.7/site-packages/vint/bootstrap.py", line 22, in init_cli', 
   '    cli.start()', 
   '  File "/usr/local/lib/python2.7/site-packages/vint/linting/cli.py", line 26, in start', 
   '    config_dict = self._build_config_dict(env)',
   '  File "/usr/local/lib/python2.7/site-packages/vint/linting/cli.py", line 56, in _build_config_dict', 
   '    ConfigDefaultSource(env),', 
   '  File "/usr/local/lib/python2.7/site-packages/vint/linting/config/config_file_source.py", line 12, in __init__', 
   ' with config_file_path.open() as file_obj:', 
   '  File "/usr/local/lib/python2.7/site-packages/pathlib.py", line 1077, in open', 
   '    return io.open(str(self), mode, buffering, encoding, errors, newline)', 
   'LookupError: unknown encoding: ', '']
syntastic: warning: checker vim/vint: unrecognized error format (crashed checker?)
syntastic: 255.849312: preprocess: []
syntastic: 255.849533: raw loclist: []
syntastic: 255.849727: getLocList: checker vim/vint returned 1
syntastic: 255.849863: vim/vint raw: []
syntastic: 255.850016: quiet_messages filter: {}
syntastic: 255.850130: getLocList: checker vim/vint run in 0.328544s
syntastic: 255.850399: aggregated: {'_sorted': 0, '_name': '', '_owner': 2, '_columns': 1, '_rawLoclist': []}

It appears this problem has cropped up with other linters, as well. Maybe a null value is being passed as an argument to io.open?

File "/usr/local/lib/python2.7/site-packages/pathlib.py", line 1077, in open
    return io.open(str(self), mode, buffering, encoding, errors, newline)
LookupError: unknown encoding: 

I'd dig through the traceback in more detail, but I don't know python at all. :\

rlue commented 7 years ago

Update, this issue only occurs in MacVim, no problem in Terminal.

Kuniwak commented 7 years ago

Update, this issue only occurs in MacVim, no problem in Terminal.

Hmm, it seems strange.

Vint has a feature that guess file encoding, and this feature got something wrong. What file encoding are you using?

rlue commented 7 years ago

UTF-8

Kuniwak commented 7 years ago

Thank you.

What file encoding are you using for config files such as ~/.vintrc?

rlue commented 7 years ago

There's a .vintrc?? (Clearly, I'm new at this.)

I don't have a .vintrc file (I checked with find . -name "*vintrc*"). Should I create one and set some settings?

I did a little check on every single file in my ~/.vim/ directory – the only non-UTF-8 files are git indices and objects from my various vim plugins, and all my vimundo files.

(I don't actually understand the command I used below; I just lifted it from this blog.)

$ pwd
/Users/rlue/.vim
$ find . -type f | xargs -I {} bash -c "iconv -f utf-8 -t utf-16 {} &>/dev/null || echo {}" > utf8_fail
$ cat utf8_fail

(you don't want to see the output of cat – it's 700 lines long.)

And no – thank you.

Kuniwak commented 7 years ago

Hmm... could you print the result of the following command?:

$ file -I /usr/local/lib/python2.7/site-packages/vint/asset/default_config.yaml
rlue commented 7 years ago

/usr/local/lib/python2.7/site-packages/vint/asset/default_config.yaml: text/plain; charset=us-ascii

Kuniwak commented 7 years ago

I suspect that the module "chardet" (Vint is using this module) returned an unexpected result.

Could you try the following script?

# test.py
import pprint
import chardet
import sys

file_path = sys.argv[1]
print("Checking: `{0}`".format(file_path))

with open(file_path, mode='rb') as f:
    bytes_seq = f.read()
    pprint.pprint(chardet.detect(bytes_seq))
$ python ./test.py /usr/local/lib/python2.7/site-packages/vint/asset/default_config.yaml
{'confidence': 0.99, 'encoding': 'utf-8'}
rlue commented 7 years ago
Checking: `/usr/local/lib/python2.7/site-packages/vint/asset/default_config.yaml`
{'confidence': 1.0, 'encoding': 'ascii'}
Kuniwak commented 7 years ago

Hmmmmm...! it seems strange! 😰

rlue commented 7 years ago

Very strange indeed! FWIW, the file appears as UTF-8 in vim, and if I add non-ascii characters to it (like “éâ” or “臭小孩”), vim still says it's UTF-8, but chardet says it's ISO-8859-2?? (confidence > .85)

Thanks for being so responsive. I'll take a closer look at it tonight and tell you if I come up with anything.

rlue commented 7 years ago

So I posted about this on reddit, and somebody helped me get one step closer to the answer:

If I launch GUI vim from the Finder, I get the error.
But if I launch GUI vim from the terminal (with mvim), then the error goes away!

Clearly this is an issue with the way MacVim is implemented and not with vint itself. Sorry for the trouble!

rlue commented 7 years ago

EDIT: @lcd047 figured it out! It's the LC_CTYPE environment variable. Still don't know what to do about it, though.


So I've been investigating this problem a little further. @lcd047 (from Syntastic) suggested it might be wise to look at the output of :echo system('env'). I thought I'd share just in case you found it useful.

I ran the command in both settings (invoking from terminal and invoking from Finder), then removed all the identical lines. Here's what was left:

Launched from the terminal, it looks like this:

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
TERM_PROGRAM_VERSION=361.1
TERM_SESSION_ID=510177A0-89AD-482B-93E8-313C3DD5A225
SHLVL=2
LC_CTYPE=UTF-8

and launched from the Finder, it looks like this:

SHLVL=1
rlue commented 7 years ago

So @lcd407 totally figured it out. The problem is that Finder doesn't preserve locales. If I set let g:syntastic_vim_vint_exe = 'LC_CTYPE=UTF-8 vint', then everything works fine

I'm reopening this issue per his/her suggestion:

Also, vint should provide some kind of fallback when locales are not available.

Thank you @kuniwak!

Kuniwak commented 7 years ago

Thanks for sharing the cause! 🎉

I'll fix it later, but also you can send PullRequest to solve it. Would you send the PullRequest?

rlue commented 7 years ago

I wish I could, but I really don't know python at all! I'd just wind up making your code worse, I think, so I'll leave this one to you ;)

Kuniwak commented 7 years ago

OK, I'll fix it later!

pixelastic commented 7 years ago

I have a similar issue (and similar to #225). Except that in my case, it does not even work from the terminal, even if setting LC_CTYPE=UTF-8.

The python encoding test script yields the following results:

Checking: `/home/tim/.local/lib/python2.7/site-packages/vint/asset/default_config.yaml`
{'confidence': 1.0, 'encoding': 'ascii', 'language': ''}