syntastic icon indicating copy to clipboard operation
syntastic copied to clipboard

Puppet parser validate not reporting for 'Syntax error at end of file'

Open Joshua-Snapp opened this issue 8 years ago • 3 comments

I noticed if I left a closing brace off at the end of a standard Puppet manifest .pp file, Syntastic would fail to report the error generated by the puppet parser validate command.

Here's the super simple Puppet manifest code that should reproduce what I'm reporting. I just threw that bit of code in a test.pp file.

class test {

I enabled Syntastic debugging. let g:syntastic_debug = 3

Here's the Syntastic debug info found in :messages.

"test.pp" [New] 1L, 13C written
syntastic: 74.586135: g:syntastic_version = '3.8.0-14 (Vim 800, Linux)'
syntastic: 74.586246: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote = '
', &autochdir = 0, &shellxescape = ''
syntastic: 74.586541: UpdateErrors (auto): default checkers
syntastic: 74.586781: CacheErrors: default checkers
syntastic: 74.587269: g:syntastic_aggregate_errors = 0
syntastic: 74.587418: getcwd() = '/home/jksnapp/itecs/puppetcode/forks/realmlinux-daniel'
syntastic: 74.588668: CacheErrors: Invoking checker: puppet/puppet
syntastic: 74.899402: system: command run in 0.310503s
syntastic: 74.899965: SyntasticMake: called with options: {'errorformat': '%-Gerr: Try ''puppet help parser validate'' for usage,%-GError: Try ''puppet help parser vali
date'' for usage,%A%t%*[a-zA-Z]: %m at %f:%l:%c,%A%t%*[a-zA-Z]: %m at %f:%l', 'makeprg': 'puppet parser validate --color=false test.pp'}
syntastic: 75.422439: system: command run in 0.522203s
syntastic: 75.422596: checker output: ['Error: Could not parse for environment production: Syntax error at end of file  in /home/jksnapp/itecs/puppetcode/forks/realmlin
ux-daniel/test.pp', '']
syntastic: 75.422918: raw loclist: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Error: Could not parse for en
vironment production: Syntax error at end of file  in /home/jksnapp/itecs/puppetcode/forks/realmlinux-daniel/test.pp'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'v
col': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 75.423099: getLocList: checker puppet/puppet returned 1
syntastic: 75.423212: puppet/puppet raw: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'Error: Could not parse
for environment production: Syntax error at end of file  in /home/jksnapp/itecs/puppetcode/forks/realmlinux-daniel/test.pp'}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid':
 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 75.423392: quiet_messages filter: {}
syntastic: 75.423504: getLocList: checker puppet/puppet run in 0.834744s
syntastic: 75.512685: system: command run in 0.088729s
syntastic: 75.513061: CacheErrors: Invoking checker: puppet/puppetlint
syntastic: 75.513519: SyntasticMake: called with options: {'errorformat': '%t%*[a-zA-Z] %m at %f:%l', 'makeprg': 'puppet-lint --no-class_inherits_from_params_class-chec
k --no-80chars-check --log-format "%{KIND} [%{check}] %{message} at %{fullpath}:%{line}" test.pp'}
syntastic: 75.602594: system: command run in 0.088810s
syntastic: 75.602739: checker output: ['']
syntastic: 75.602970: raw loclist: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 75.603111: getLocList: checker puppet/puppetlint returned 0
syntastic: 75.603212: puppet/puppetlint raw: [{'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 75.603349: quiet_messages filter: {}
syntastic: 75.603446: getLocList: checker puppet/puppetlint run in 0.090276s
syntastic: 75.603651: aggregated: {'_sorted': 0, '_name': '', '_owner': 1, '_columns': 1, '_rawLoclist': []}

You can see how checker puppet/puppet reports 1 and there's checker output, raw loclist and puppet/puppet raw content. For some reason, Syntastic just moves on to the checker puppet/puppetlint without reporting the puppet/puppet checker error.

I inserted a "^" in front of the opening brace just to record what happens when the puppet/puppet checker reports correctly.

"test.pp" 1L, 14C written
syntastic: 382.165520: g:syntastic_version = '3.8.0-14 (Vim 800, Linux)'
syntastic: 382.165668: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shelltemp = 1, &shellxquote =
'', &autochdir = 0, &shellxescape = ''
syntastic: 382.166018: UpdateErrors (auto): default checkers
syntastic: 382.166280: CacheErrors: default checkers
syntastic: 382.166795: g:syntastic_aggregate_errors = 0
syntastic: 382.166965: getcwd() = '/home/jksnapp/itecs/puppetcode/forks/realmlinux-daniel'
syntastic: 382.167378: CacheErrors: Invoking checker: puppet/puppet
syntastic: 382.167811: SyntasticMake: called with options: {'errorformat': '%-Gerr: Try ''puppet help parser validate'' for usage,%-GError: Try ''puppet help parser val
idate'' for usage,%A%t%*[a-zA-Z]: %m at %f:%l:%c,%A%t%*[a-zA-Z]: %m at %f:%l', 'makeprg': 'puppet parser validate --color=false test.pp'}
syntastic: 382.690384: system: command run in 0.522301s
syntastic: 382.690513: checker output: ['Error: Could not parse for environment production: Syntax error at ''^'' at /home/jksnapp/itecs/puppetcode/forks/realmlinux-dan
iel/test.pp:1:12', '']
syntastic: 382.690860: raw loclist: [{'lnum': 1, 'bufnr': 1, 'col': 12, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'Could not parse for enviro
nment production: Syntax error at ''^'''}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 382.691045: getLocList: checker puppet/puppet returned 1
syntastic: 382.691167: puppet/puppet raw: [{'lnum': 1, 'bufnr': 1, 'col': 12, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'Could not parse for
environment production: Syntax error at ''^'''}, {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ''}]
syntastic: 382.691343: quiet_messages filter: {}
syntastic: 382.691450: getLocList: checker puppet/puppet run in 0.523974s
syntastic: 382.691736: aggregated: {'_sorted': 0, '_name': 'puppet (puppet)', '_owner': 1, '_columns': 1, '_rawLoclist': [{'lnum': 1, 'bufnr': 1, 'col': 12, 'valid': 1,
 'vcol': 0, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'Could not parse for environment production: Syntax error at ''^'''}]}

This time the puppet/puppet checker still returns 1 and there's still content in the checker output, raw loclist and puppet/puppet raw, but Syntastic does not proceed to puppet/puppetlint checker. Instead, it correctly populates aggregated and reports the error.

Any help in resolving this would be greatly appreciated. If it's something on my end, just point me in the right direction please.

Thanks!

Joshua-Snapp avatar Jan 20 '17 03:01 Joshua-Snapp

Syntastic uses loclists to keep track of checker errors, and loclist items need at least two things to be useful: a line number, and a message. Without a line number you can't jump to the error in the source file, which is the main purpose of syntastic. The error message produced by puppet above doesn't have a line number.

A case can be made that said message would still be highly relevant. However, including it would involve looking for it explicitly, and parsing puppet error messages is already unreasonable (cf. #1435). The puppet checker should never been added to syntastic, and is a prime candidate for deletion in a future version. Sorry about that.

A better way to get this fixed would be to ask puppet developers for something like well-formed JSON output, including at least line numbers and messages.

lcd047 avatar Jan 20 '17 07:01 lcd047

Hey, first of all a Happy New Year and a big thanks for this great vim plugin!

I found this issue after running into similar syntax errors from time to time. Even after years of writing puppet-code...
Syntastic says everything is fine, I want to start a puppet run for a test and suddenly got an unexpected syntax error :( My fix is nothing else then another workaround for the puppet parser. But after this will make my life a bit easier, I want to offer that as a pull request.

slm0n87 avatar Jan 06 '19 19:01 slm0n87

Actually, puppet now seems to be able to output JSON. It doesn't seem to work for parser validate though. :smile:

lcd047 avatar Jan 06 '19 20:01 lcd047