From 2721ac1f1f75cc0bfb9939f4230dfc1479cd5744 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Thu, 30 Aug 2018 15:37:34 +0800 Subject: [PATCH] (GH-51) Add handling of errors when loading classes Previously if there was an error while parsing classes, it would cascade the error and crash the sidecar. This commit catches the error and gracefully continues. --- lib/puppet-languageserver-sidecar/puppet_helper.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/puppet-languageserver-sidecar/puppet_helper.rb b/lib/puppet-languageserver-sidecar/puppet_helper.rb index 5771ba98..d23ec226 100644 --- a/lib/puppet-languageserver-sidecar/puppet_helper.rb +++ b/lib/puppet-languageserver-sidecar/puppet_helper.rb @@ -47,8 +47,12 @@ def self.retrieve_classes(cache, options = {}) classes = PuppetLanguageServer::Sidecar::Protocol::PuppetClassList.new manifest_path_list.each do |manifest_path| Dir.glob("#{manifest_path}/**/*.pp").each do |manifest_file| - if path_has_child?(options[:root_path], manifest_file) - classes.concat(load_classes_from_manifest(cache, manifest_file)) + begin + if path_has_child?(options[:root_path], manifest_file) + classes.concat(load_classes_from_manifest(cache, manifest_file)) + end + rescue StandardError => err + PuppetLanguageServerSidecar.log_message(:error, "[PuppetHelper::retrieve_classes] Error loading manifest #{manifest_file}: #{err} #{err.backtrace}") end end end @@ -176,7 +180,6 @@ def self.load_classes_from_manifest(cache, manifest_file) end file_content = File.open(manifest_file, 'r:UTF-8') { |f| f.read } - parser = Puppet::Pops::Parser::Parser.new result = nil begin