summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-11-18 14:10:14 -0800
committerPete Higgins <pete@peterhiggins.org>2020-12-01 16:12:04 -0800
commitb1147a7f22ffa5a6ae784f5b853e6abf139a6b3c (patch)
treec444208fc2aa8daecca53d028455d217729d0882
parent7f1c82e83e73636ca5adaec0eb77eee833654c68 (diff)
downloadchef-b1147a7f22ffa5a6ae784f5b853e6abf139a6b3c.tar.gz
Cleanup some error handling.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/audit/fetcher/automate.rb3
-rw-r--r--lib/chef/audit/fetcher/chef_server.rb4
-rw-r--r--lib/chef/audit/runner.rb5
-rw-r--r--spec/unit/audit/fetcher/automate_spec.rb2
4 files changed, 6 insertions, 8 deletions
diff --git a/lib/chef/audit/fetcher/automate.rb b/lib/chef/audit/fetcher/automate.rb
index 8d7fcc5bdd..ea13a18389 100644
--- a/lib/chef/audit/fetcher/automate.rb
+++ b/lib/chef/audit/fetcher/automate.rb
@@ -47,7 +47,8 @@ class Chef
config["token"] = Chef::Config[:data_collector][:token]
if config["token"].nil?
- raise "No data-collector token set, which is required by the chef-automate fetcher. " \
+ raise Inspec::FetcherFailure,
+ "No data-collector token set, which is required by the chef-automate fetcher. " \
"Set the `data_collector.token` configuration parameter in your client.rb " \
'or use the "chef-server-automate" reporter which does not require any ' \
"data-collector settings and uses Chef Server to fetch profiles."
diff --git a/lib/chef/audit/fetcher/chef_server.rb b/lib/chef/audit/fetcher/chef_server.rb
index d28aba0a8b..f88e4b74ad 100644
--- a/lib/chef/audit/fetcher/chef_server.rb
+++ b/lib/chef/audit/fetcher/chef_server.rb
@@ -73,7 +73,7 @@ class Chef
if archive.nil?
path = @target.respond_to?(:path) ? @target.path : path
- raise "Unable to find requested profile on path: '#{path}' on the Automate system."
+ raise Inspec::FetcherFailure, "Unable to find requested profile on path: '#{path}' on the Automate system."
end
Inspec::Log.debug("Archive stored at temporary location: #{archive.path}")
@@ -105,7 +105,7 @@ class Chef
end
msg = "Received HTTP error #{code}"
Chef::Log.error msg
- raise msg if @raise_if_unreachable
+ raise Inspec::FetcherFailure, msg
end
def to_s
diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb
index 4168329850..45b2d206ba 100644
--- a/lib/chef/audit/runner.rb
+++ b/lib/chef/audit/runner.rb
@@ -113,13 +113,10 @@ class Chef
r = runner.report
logger.debug "Audit Report #{r}"
r
-=begin
rescue Inspec::FetcherFailure => e
- err = "Cannot fetch all profiles: #{profiles}. Please make sure you're authenticated and the server is reachable. #{e.message}"
- failed_report(err)
+ failed_report("Cannot fetch all profiles: #{profiles}. Please make sure you're authenticated and the server is reachable. #{e.message}")
rescue => e
failed_report(e.message)
-=end
end
# In case InSpec raises a runtime exception without providing a valid report,
diff --git a/spec/unit/audit/fetcher/automate_spec.rb b/spec/unit/audit/fetcher/automate_spec.rb
index ea471a1a22..b4ed3f4f8c 100644
--- a/spec/unit/audit/fetcher/automate_spec.rb
+++ b/spec/unit/audit/fetcher/automate_spec.rb
@@ -105,7 +105,7 @@ describe Chef::Audit::Fetcher::Automate do
expect {
Chef::Audit::Fetcher::Automate.resolve(compliance: "namespace/profile_name")
- }.to raise_error(/No data-collector token set/)
+ }.to raise_error(Inspec::FetcherFailure, /No data-collector token set/)
end
it "includes the data collector token" do