Permalink
Browse files

make compile errors more robust and add recipe_not_found handling

  • Loading branch information...
1 parent e8131da commit abefd661954fd533c227e17ff74065bf114e8b24 @lamont-granquist lamont-granquist committed Jul 13, 2012
@@ -206,6 +206,10 @@ def recipe_file_loaded(path)
def recipe_file_load_failed(path, exception)
end
+ # Called when a recipe cannot be resolved
+ def recipe_not_found(exception)
+ end
+
# Called when recipes have been loaded.
def recipe_load_complete
end
@@ -175,6 +175,11 @@ def file_load_failed(path, exception)
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)
@@ -33,11 +33,16 @@ def initialize(path, exception)
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 @@ def culprit_file
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
@@ -75,12 +75,11 @@ def self.resource_failed(resource, action, exception)
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
@@ -77,6 +77,9 @@ def load(run_list_expansion)
# TODO: timh/cw, 5-14-2010: It's distasteful to be including
# the DSL in a class outside the context of the DSL
include_recipe(recipe)
+ rescue Chef::Exceptions::RecipeNotFound => e
+ @events.recipe_not_found(e)
+ raise
rescue Exception => e
path = resolve_recipe(recipe)
@events.recipe_file_load_failed(path, e)

0 comments on commit abefd66

Please sign in to comment.