File tree Expand file tree Collapse file tree 2 files changed +37
-3
lines changed
vendor/gems/process_manager-0.0.13/lib/process_manager Expand file tree Collapse file tree 2 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -207,5 +207,35 @@ class InstanceAgentConfigTest < InstanceAgentTestCase
207207 config_file . delete
208208 end
209209 end
210+
211+ should 'raise readable error on config load failure' do
212+ config_file = Tempfile . new ( "config.yml" )
213+ begin
214+ config_file . write <<~FILE
215+ this is not valid
216+ FILE
217+
218+ config_file . close
219+
220+ InstanceAgent ::Config . config [ :config_file ] = config_file . path
221+ exception = assert_raise ( RuntimeError ) { InstanceAgent ::Config . load_config }
222+
223+ message = exception . to_s
224+
225+ assert_match ( /^An error occurred loading the CodeDeploy agent config file at #{ config_file . path } . Error message:.*$/ , message )
226+ ensure
227+ config_file . delete
228+ end
229+ end
230+
231+ should 'raise readable error on config file not found' do
232+ fake_path = "/path/does/not/exist/not_here.yml"
233+ InstanceAgent ::Config . config [ :config_file ] = "/path/does/not/exist/not_here.yml"
234+ exception = assert_raise ( RuntimeError ) { InstanceAgent ::Config . load_config }
235+
236+ message = exception . to_s
237+
238+ assert_match ( /^The config file #{ fake_path } does not exist or is not readable$/ , message )
239+ end
210240 end
211241end
Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ def self.validate_config
1818
1919 def self . load_config
2020 if File . readable? ( config [ :config_file ] )
21- file_config = YAML . load ( File . read ( config [ :config_file ] ) ) . symbolize_keys
22- config . update ( file_config )
23- config_loaded_callbacks . each { |c | c . call }
21+ begin
22+ file_config = YAML . load ( File . read ( config [ :config_file ] ) ) . symbolize_keys
23+ config . update ( file_config )
24+ config_loaded_callbacks . each { |c | c . call }
25+ rescue Exception => ex
26+ raise "An error occurred loading the CodeDeploy agent config file at #{ config [ :config_file ] } . Error message: #{ ex } "
27+ end
2428 else
2529 raise "The config file #{ config [ :config_file ] } does not exist or is not readable"
2630 end
You can’t perform that action at this time.
0 commit comments