diff options
author | Lamont Granquist <lamont@opscode.com> | 2012-07-13 15:09:19 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2012-07-13 15:09:19 -0700 |
commit | abefd661954fd533c227e17ff74065bf114e8b24 (patch) | |
tree | 10dc92845df581fd931a264ea7bc0dac66ffe653 /chef/lib/chef/formatters | |
parent | e8131da06c283bc0b336b7e69573783982982ad8 (diff) | |
download | chef-abefd661954fd533c227e17ff74065bf114e8b24.tar.gz |
make compile errors more robust and add recipe_not_found handling
Diffstat (limited to 'chef/lib/chef/formatters')
-rw-r--r-- | chef/lib/chef/formatters/base.rb | 5 | ||||
-rw-r--r-- | chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb | 18 | ||||
-rw-r--r-- | chef/lib/chef/formatters/error_mapper.rb | 3 |
3 files changed, 18 insertions, 8 deletions
diff --git a/chef/lib/chef/formatters/base.rb b/chef/lib/chef/formatters/base.rb index 2c1befb901..d8b2e49d8e 100644 --- a/chef/lib/chef/formatters/base.rb +++ b/chef/lib/chef/formatters/base.rb @@ -175,6 +175,11 @@ class Chef display_error(description) end + def recipe_not_found(exception) + description = ErrorMapper.file_load_failed(nil, exception) + display_error(description) + end + # Delegates to #file_loaded def library_file_loaded(path) file_loaded(path) diff --git a/chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb b/chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb index e892217d84..ca359d6271 100644 --- a/chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +++ b/chef/lib/chef/formatters/error_inspectors/compile_error_inspector.rb @@ -33,11 +33,16 @@ class Chef end def add_explanation(error_description) - error_description.section(exception.class.name, exception.message) - - traceback = filtered_bt.map {|line| " #{line}"}.join("\n") - error_description.section("Cookbook Trace:", traceback) - error_description.section("Relevant File Content:", context) + case exception + when Chef::Exceptions::RecipeNotFound + error_description.section(exception.class.name, exception.message) + else + error_description.section(exception.class.name, exception.message) + + traceback = filtered_bt.map {|line| " #{line}"}.join("\n") + error_description.section("Cookbook Trace:", traceback) + error_description.section("Relevant File Content:", context) + end end def context @@ -80,7 +85,8 @@ class Chef end def filtered_bt - exception.backtrace.select {|l| l =~ /^#{Chef::Config.file_cache_path}/ } + r = exception.backtrace.select {|l| l =~ /^#{Chef::Config.file_cache_path}/ } + return r.count > 0 ? r : exception.backtrace end end diff --git a/chef/lib/chef/formatters/error_mapper.rb b/chef/lib/chef/formatters/error_mapper.rb index 7a3ee99a23..2140c638bc 100644 --- a/chef/lib/chef/formatters/error_mapper.rb +++ b/chef/lib/chef/formatters/error_mapper.rb @@ -75,12 +75,11 @@ class Chef def self.file_load_failed(path, exception) error_inspector = ErrorInspectors::CompileErrorInspector.new(path, exception) - headline = "Error compiling #{path}" + headline = "Recipe Compile Error" + ( path ? " in #{path}" : "" ) description = ErrorDescription.new(headline) error_inspector.add_explanation(description) description end - end end end |