From 3647114c381a02b9fe2024df8afc37021df1c058 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 14 Dec 2016 09:08:05 -0600 Subject: [PATCH] (MODULES-4056) Helpful Error if No Sources Enabled Previously, when there were no sources enabled, Puppet would attempt to loop over a non-existent set of packages pulled back from listing a set of packages locally. Unfortunately this is due to an issue in Chocolatey that requires at least one source to be enabled to produce the local set of installed packages: https://github.com/chocolatey/choco/issues/661 Instead of allowing Puppet to fail on a nil:NilClass error, provide a helpful and actionable message instead. --- lib/puppet/provider/package/chocolatey.rb | 1 + spec/unit/puppet/provider/package/chocolatey_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/puppet/provider/package/chocolatey.rb b/lib/puppet/provider/package/chocolatey.rb index 0bd5a68e..d01ad0d5 100644 --- a/lib/puppet/provider/package/chocolatey.rb +++ b/lib/puppet/provider/package/chocolatey.rb @@ -199,6 +199,7 @@ def self.instances process.each_line do |line| line.chomp! if line.empty? or line.match(/Reading environment variables.*/); next; end + raise Puppet::Error, "At least one source must be enabled." if line.match(/Unable to search for packages.*/) if choco_exe values = line.split('|') else diff --git a/spec/unit/puppet/provider/package/chocolatey_spec.rb b/spec/unit/puppet/provider/package/chocolatey_spec.rb index d29099f0..e6fa57be 100644 --- a/spec/unit/puppet/provider/package/chocolatey_spec.rb +++ b/spec/unit/puppet/provider/package/chocolatey_spec.rb @@ -473,6 +473,14 @@ :name => 'package2' } end + + it "should return nil on error" do + provider.expects(:execpipe).yields(StringIO.new(%Q(Unable to search for packages when there are no soures enabled for packages and none were passed as arguments.\n))) + + expect { + provider.instances + }.to raise_error(Puppet::Error, /At least one source must be enabled./) + end end context "with posh choco client" do