diff options
author | Naomi Reeves <nreeves@fb.com> | 2020-08-12 14:04:15 -0700 |
---|---|---|
committer | Naomi Reeves <NaomiReeves@users.noreply.github.com> | 2020-08-20 22:17:53 -0700 |
commit | 00d626c4f33eacca07966237579df0cba56df25e (patch) | |
tree | 86764a4af31852909291765c0ae6e434e5005b96 | |
parent | fa84abaedf07d8d5aed8ee7509b3370140797835 (diff) | |
download | chef-00d626c4f33eacca07966237579df0cba56df25e.tar.gz |
rescue all configuration errors and re-raise
Signed-off-by: Naomi Reeves <NaomiReeves@users.noreply.github.com>
-rw-r--r-- | lib/chef/application.rb | 11 | ||||
-rw-r--r-- | spec/unit/application/client_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/application_spec.rb | 10 |
3 files changed, 13 insertions, 12 deletions
diff --git a/lib/chef/application.rb b/lib/chef/application.rb index 322c10460d..257f993bbe 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -96,7 +96,11 @@ class Chef # Parse configuration (options and config file) def configure_chef parse_options - load_config_file + begin + load_config_file + rescue Exception => e + Chef::Application.fatal!(e.message, Chef::Exceptions::ConfigurationError.new) + end chef_config.export_proxies chef_config.init_openssl File.umask chef_config[:umask] @@ -151,8 +155,6 @@ class Chef def apply_extra_config_options(extra_config_options) chef_config.apply_extra_config_options(extra_config_options) - rescue ChefConfig::UnparsableConfigOption => e - Chef::Application.fatal!(e.message) end # Set the specific recipes to Chef::Config if the recipes are valid @@ -352,7 +354,8 @@ class Chef logger.fatal("Configuration error #{error.class}: #{error.message}") filtered_trace = error.backtrace.grep(/#{Regexp.escape(config_file_path)}/) filtered_trace.each { |line| logger.fatal(" " + line ) } - Chef::Application.fatal!("Aborting due to error in '#{config_file_path}'", error) + raise Chef::Exceptions::ConfigurationError.new("Aborting due to error in '#{config_file_path}': #{error}") + # Chef::Application.fatal!("Aborting due to error in '#{config_file_path}'", Chef::Exceptions::ConfigurationError.new(error)) end # This is a hook for testing diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 004debf5ad..6977e4f108 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -192,7 +192,7 @@ describe Chef::Application::Client, "reconfigure" do context "with an empty value" do it "should terminate with message" do - expect(Chef::Application).to receive(:fatal!).with('Unparsable config option ""').and_raise("so ded") + expect(Chef::Application).to receive(:fatal!).with('Unparsable config option ""', ChefConfig::ConfigurationError.new).and_raise("so ded") ARGV.replace(["--config-option", ""]) expect { app.reconfigure }.to raise_error "so ded" end @@ -200,7 +200,7 @@ describe Chef::Application::Client, "reconfigure" do context "with an invalid value" do it "should terminate with message" do - expect(Chef::Application).to receive(:fatal!).with('Unparsable config option "asdf"').and_raise("so ded") + expect(Chef::Application).to receive(:fatal!).with('Unparsable config option "asdf"', ChefConfig::ConfigurationError.new).and_raise("so ded") ARGV.replace(["--config-option", "asdf"]) expect { app.reconfigure }.to raise_error "so ded" end diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index aa916d0793..b84f0c99f2 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -491,16 +491,14 @@ describe Chef::Application do describe "configuration errors" do before do - expect(Process).to receive(:exit) + allow(Process).to receive(:exit).and_return(true) end def raises_informative_fatals_on_configure_chef config_file_regexp = Regexp.new @app.config[:config_file] - expect(Chef::Log).to receive(:fatal) - .with(/Configuration error/) - expect(Chef::Log).to receive(:fatal) - .with(config_file_regexp) - .at_least(1).times + expect(Chef::Log).to receive(:fatal).with(/Configuration error/) + expect(Chef::Log).to receive(:fatal).with(config_file_regexp) + expect(Process).to receive(:exit).with(43).and_return(true) @app.configure_chef end |