Skip to content

Commit

Permalink
(MODULES-4056) Helpful Error if No Sources Enabled
Browse files Browse the repository at this point in the history
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:
chocolatey/choco#661

Instead of allowing Puppet to fail on a nil:NilClass error, provide
a helpful and actionable message instead.
  • Loading branch information
ferventcoder committed Dec 14, 2016
1 parent 650cc07 commit 3647114
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/puppet/provider/package/chocolatey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/puppet/provider/package/chocolatey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3647114

Please sign in to comment.