lib/puppet-check/puppet_parser.rb in puppet-check-1.5.1 vs lib/puppet-check/puppet_parser.rb in puppet-check-1.6.0
- old
+ new
@@ -19,17 +19,31 @@
# check puppet syntax
begin
Puppet::Face[:parser, :current].validate(file)
# this is the actual error that we need to rescue Puppet::Face from
rescue SystemExit
+ # puppet 5.4-5.x has a new validator output format and eof errors have fake dir env info
+ if Puppet::PUPPETVERSION.to_f >= 5.4
+ next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')}")
# puppet 5.0-5.2 can only do one error per line and outputs fake dir env info
- next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '')}") if Puppet::PUPPETVERSION.to_f >= 5.0 && Puppet::PUPPETVERSION.to_f < 5.3
- # puppet < 5 parser output style
+ elsif Puppet::PUPPETVERSION.to_f >= 5.0 && Puppet::PUPPETVERSION.to_f < 5.3
+ next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '')}")
+ end
+ # puppet < 5 and 5.3 parser output style
next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}")
end
# initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit
- warnings = errors.empty? ? "#{file}:" : "#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
+ warnings = "#{file}:"
+ unless errors.empty?
+ # puppet 5.4-5.x has a new validator output format
+ if Puppet::PUPPETVERSION.to_f >= 5.4
+ warnings << "\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
+ # puppet <= 5.3 validator output format
+ else
+ warnings << "\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
+ end
+ end
Puppet::Util::Log.close_all
# check puppet style
if style
require 'puppet-lint'