vim-syntastic / syntastic

Syntax checking hacks for vim
Do What The F*ck You Want To Public License
11.3k stars 1.14k forks source link

puppet version check error #2355

Closed lofic closed 3 years ago

lofic commented 3 years ago

Hello,

I get :

syntastic: error: checker output:
2021-02-19 17:04:29.076087 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
6.21.0
syntastic: error: checker puppet/puppet: can't parse version string (abnormal termination?)

It seems to be during the check of the puppet version

It can't parse this for the version :

2021-02-19 17:04:29.076087 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
6.21.0

I don't know how to suppress the warning or set the version forcibly.

It happens on Debian 10 where puppet is installed with the third part puppetlabs repos. I got that on a laptop with Debian, a VM with Debian, and Debian in a WSL.

In a shell it is fine :

$ puppet --version
6.21.0

$ which facter
/opt/puppetlabs/bin/facter

$ which puppet
/opt/puppetlabs/bin/puppet

In vim, :echo system('puppet --version') gives :

6.21.0

:echo $SHELL gives :

/bin/bash

:SyntasticInfo gives :

Syntastic version: 3.10.0 (Vim 801, Linux, GUI)
Info for filetype: puppet
Global mode: active
Filetype puppet is active
The current file will be checked automatically
Available checkers: puppet puppetlint
Currently enabled checkers: puppet puppetlint

Setting g:syntastic_debug to 3,

syntastic: 7.311380: g:syntastic_version = '3.10.0 (Vim 801, Linux, GUI)'
syntastic: 7.311815: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote = '', &autochdir = 0, &she
llxescape = ''
syntastic: 7.313290: UpdateErrors: default checkers
syntastic: 7.313938: CacheErrors: default checkers
syntastic: 7.315695: g:syntastic_aggregate_errors = 0
syntastic: 7.316113: $TERM = 'xterm-256color'
syntastic: 7.316369: $TMPDIR = ''
syntastic: 7.316658: $PATH = '/home/lofic/google-cloud-sdk/bin:/home/lofic/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:/opt/puppetlabs/bin:/home/lofic/Documents/scripts:/sbin:/home/lofic/.gem/bin:/opt/puppetlabs/puppet/bin:/home/lofic/go/bin:/home/lofic/.local/bin:/home/lofic/.npm-packages/bin:/home/lofic/bin'
syntastic: 7.316865: getcwd() = '/home/lofic/Documents/labs/puppet-modules/yum'
syntastic: 7.318356: CacheErrors: Invoking checker: puppet/puppet
syntastic: 8.062435: system: command run in 0.743593s
syntastic: 8.062915: puppet/puppet: getVersion: 'puppet --version': ['2021-02-19 17:26:04.596718 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C', '6.21.0', '']
syntastic: error: checker output:
2021-02-19 17:26:04.596718 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
6.21.0
syntastic: error: checker puppet/puppet: can't parse version string (abnormal termination?)
syntastic: 8.065181: SyntasticMake: called with options: {'errorformat': '%-Gerr: Try ''puppet help parser validate'' for usage,%-GError: Try ''puppet help parser validate'' for usage,%A%t%*
[a-zA-Z]: %m at %f:%l:%c,%A%t%*[a-zA-Z]: %m at %f:%l,%A%t%*[a-zA-Z]: Could not parse for environment production: %m (file: %f\, line: %l\, column: %c)', 'makeprg': 'puppet --color=false --pa
rseonly manifests/init.pp'}
syntastic: 8.830766: system: command run in 0.764668s
syntastic: 8.831337: getLocList: checker puppet/puppet returned 1
syntastic: 8.831562: getLocList: checker puppet/puppet run in 1.513106s
syntastic: 8.999501: system: command run in 0.167516s
syntastic: 8.999628: puppet/puppetlint: getVersion: 'puppet-lint --version': ['puppet-lint 2.3.6', '']
syntastic: 8.999744: puppet/puppetlint: puppet-lint version = [2, 3, 6]
syntastic: 8.999923: CacheErrors: Invoking checker: puppet/puppetlint
syntastic: 9.000343: SyntasticMake: called with options: {'errorformat': '%t%*[a-zA-Z] %m at %f:%l', 'makeprg': 'puppet-lint --log-format "%{KIND} [%{check}] %{message} at %{fullpath}:%{line
}" manifests/init.pp'}
syntastic: 9.157948: system: command run in 0.157367s
syntastic: 9.158258: getLocList: checker puppet/puppetlint returned 0
syntastic: 9.158420: getLocList: checker puppet/puppetlint run in 0.158422s
syntastic: 237.375714: g:syntastic_version = '3.10.0 (Vim 801, Linux, GUI)'
syntastic: 237.376177: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote = '', &autochdir = 0, &s
hellxescape = ''
syntastic: 237.377200: UpdateErrors: default checkers
syntastic: 237.377838: CacheErrors: default checkers
syntastic: 237.379444: g:syntastic_aggregate_errors = 0
syntastic: 237.379994: getcwd() = '/home/lofic/Documents/labs/puppet-modules/yum'
syntastic: 237.381099: CacheErrors: Invoking checker: puppet/puppet
syntastic: 237.381493: SyntasticMake: called with options: {'errorformat': '%-Gerr: Try ''puppet help parser validate'' for usage,%-GError: Try ''puppet help parser validate'' for usage,%A%t
%*[a-zA-Z]: %m at %f:%l:%c,%A%t%*[a-zA-Z]: %m at %f:%l,%A%t%*[a-zA-Z]: Could not parse for environment production: %m (file: %f\, line: %l\, column: %c)', 'makeprg': 'puppet --color=false --
parseonly manifests/init.pp'}
syntastic: 238.114702: system: command run in 0.732941s
syntastic: 238.114834: checker output: ['2021-02-19 17:29:54.662183 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C', 'Error: Could not parse
 application options: invalid option: --color=false', '']
syntastic: 238.115211: raw loclist: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'pattern': '', 'text': '2021-02-19 17:29:54.662183 WARN  pup
petlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'patte
rn': '', 'text': 'Error: Could not parse application options: invalid option: --color=false'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'p
attern': '', 'text': ''}]
syntastic: 238.115467: getLocList: checker puppet/puppet returned 1
syntastic: 238.115584: puppet/puppet raw: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'pattern': '', 'text': '2021-02-19 17:29:54.662183 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '',
'pattern': '', 'text': 'Error: Could not parse application options: invalid option: --color=false'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type':'', 'pattern': '', 'text': ''}]
syntastic: 238.115819: quiet_messages filter: {}
syntastic: 238.115929: getLocList: checker puppet/puppet run in 0.734735s
syntastic: 238.116203: CacheErrors: Invoking checker: puppet/puppetlint
syntastic: 238.116673: SyntasticMake: called with options: {'errorformat': '%t%*[a-zA-Z] %m at %f:%l', 'makeprg': 'puppet-lint --log-format "%{KIND} [%{check}] %{message} at %{fullpath}:%{line}" manifests/init.pp'}
syntastic: 238.294779: system: command run in 0.177846s
syntastic: 238.294903: checker output: ['']
syntastic: 238.295133: raw loclist: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'pattern': '', 'text': ''}]
syntastic: 238.295275: getLocList: checker puppet/puppetlint returned 0
syntastic: 238.295365: puppet/puppetlint raw: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'module': '', 'type': '', 'pattern': '', 'text': ''}]
syntastic: 238.295499: quiet_messages filter: {}
syntastic: 238.295578: getLocList: checker puppet/puppetlint run in 0.179273s
syntastic: 238.295784: aggregated: {'_sorted': 0, '_name': '', '_owner': 1, '_columns': 1, '_rawLoclist': []}

Regards.

Louis

lofic commented 3 years ago

I tried with :

let g:syntastic_puppet_puppet_exe='LANG=C LC_ALL=C puppet'
let g:syntastic_puppet_puppetlint_exe = "LANG=C LC_ALL=C puppet-lint"

in my ~/.vimrc

But it's not working.

lcd047 commented 3 years ago

Please post the output of :echo syntastic#util#system('puppet --version').

lofic commented 3 years ago

:echo syntastic#util#system('puppet --version') gives :

2021-02-21 15:42:02.536709 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
6.21.0
lcd047 commented 3 years ago

syntastic#util#system() differs from system() in that it sets LC_ALL= and LC_MESSAGES=C, and it uses the shell named by g:syntastic_shell (if set). The point of this is to get error messages in English rather than localized, so that syntastic can parse them. To further complicate things, version testing doesn't use syntastic_puppet_puppet_exe, it only cares about syntastic_puppet_puppet_exec. There is no way to override any of these, so basically you need to configure things so that they survive syntastic#util#system() without messing with the environment inside Vim. One way to do that might be to write a shell wrapper that sets the environment and runs puppet, then set syntastic_puppet_puppet_exec to point to it. Perhaps something like this (not tested):

#!/bin/sh
LC_ALL=C
export LC_ALL
LANG=C
export LANG
exec /path/to/puppet "$@"

According to your logs puppetlint runs without errors, it's only puppet that bails out.

lofic commented 3 years ago

Hello,

I confirm it works with your wrapper script.

But I can't figure out why it works in other contexts (i.e. on a CentOS) without the workaround.

This would be a clue for a nice solution.

Louis

lofic commented 3 years ago

Do you know a way to output messages from SyntasticCheck to the shell or a file, for more tests :

vim -c ':SyntasticCheck' -c ':q' test.pp

?

lcd047 commented 3 years ago

This would be a clue for a nice solution.

This is Vim we're talking about, a wrapper is about as nice as it gets.

Do you know a way to output messages from SyntasticCheck to the shell or a file, for more tests

For redirecting output to a file see :h :redir. If you want something that runs Vim from command line, runs a script, then exits, I used to know how to do that at some point, but I discarded that knowledge at some point, in the interest of my sanity. :smile:

Anyway, you probably don't need to go there, your problem seems to be puppet not liking "hybrid" locales, unrelated to either Vim or syntastic. You can probably reproduce it by running something like this in a terminal:

LC_ALL= LANG=C puppet --version
lofic commented 3 years ago

Hello,comparing the output of locale in a shell and in vim I've been able to reproduce in a shell :

$ LC_ALL= LANG=en_US puppet --version
2021-02-22 10:09:32.287296 WARN  puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
6.21.0

Then I found this line in my ~/.vimrc from something like 15 years ago :

let $LANG='en_US'

This was the culprit.

Setting :

let $LANG='en_US.UTF-8'

Fixes it.

Thank you for your help and patience !

Louis