Skip to content

Commit

Permalink
[CHANGED] Package Manager will now log if prepare step fails. Instead…
Browse files Browse the repository at this point in the history
… of erroring out

[#153198241]

Signed-off-by: Li Tai <ltai@pivotal.io>
Signed-off-by: Shane Lattanzio <slattanzio@pivotal.io>
  • Loading branch information
Ryan Collins authored and xtreme-shane-lattanzio committed Nov 28, 2017
1 parent 66abece commit 54da71e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/license_finder/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ def detected_package_path

def prepare
if self.class.prepare_command
_stdout, _stderr, status = Cmd.run(self.class.prepare_command)
raise "Prepare command '#{self.class.prepare_command}' failed" unless status.success?
_stdout, stderr, status = Cmd.run(self.class.prepare_command)
unless status.success?
logger.info self.class.prepare_command, 'did not succeed.', color: :red
logger.info self.class.prepare_command, stderr, color: :red
end
else
logger.debug self.class, 'no prepare step provided', color: :red
end
Expand Down
11 changes: 7 additions & 4 deletions spec/lib/license_finder/package_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ module LicenseFinder
expect { subject.prepare }.to_not raise_error
end

it 'raises exception when prepare command runs into failure' do
expect(SharedHelpers::Cmd).to receive(:run).with('sh commands').and_return(['output', nil, cmd_failure])

expect { subject.prepare }.to raise_error("Prepare command 'sh commands' failed")
it 'logs warning and exception when prepare command runs into failure' do
logger = double(:logger)
expect(SharedHelpers::Cmd).to receive(:run).with('sh commands').and_return(['output', 'failure error msg', cmd_failure])
expect(logger).to receive(:info).with('sh commands', 'did not succeed.', color: :red)
expect(logger).to receive(:info).with('sh commands', 'failure error msg', color: :red)
subject = described_class.new logger: logger
expect { subject.prepare }.to_not raise_error
end
end

Expand Down

0 comments on commit 54da71e

Please sign in to comment.