Implement recipe error reporting feature
This commit is contained in:
@@ -12,17 +12,24 @@ module Producer
|
||||
|
||||
def run!
|
||||
check_arguments!
|
||||
evaluate_recipe_file(@arguments[1])
|
||||
evaluate_recipe_file
|
||||
end
|
||||
|
||||
def check_arguments!
|
||||
print_usage_and_exit(64) unless @arguments.length == 2
|
||||
end
|
||||
|
||||
def evaluate_recipe_file(filepath)
|
||||
def evaluate_recipe_file
|
||||
recipe = Recipe.from_file(@arguments[1])
|
||||
env = Env.new(recipe)
|
||||
recipe.evaluate env
|
||||
begin
|
||||
recipe.evaluate env
|
||||
rescue Recipe::RecipeEvaluationError => e
|
||||
@stdout.puts [e.backtrace.shift, e.message].join ': '
|
||||
@stdout.puts e.backtrace
|
||||
|
||||
exit 70
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Recipe
|
||||
RecipeEvaluationError = Class.new(StandardError)
|
||||
|
||||
attr_reader :code, :filepath
|
||||
|
||||
def self.from_file(filepath)
|
||||
@@ -29,11 +31,15 @@ module Producer
|
||||
|
||||
def evaluate(env)
|
||||
if @code
|
||||
instance_eval @code
|
||||
instance_eval @code, env.current_recipe.filepath
|
||||
else
|
||||
instance_eval &@block
|
||||
end
|
||||
self
|
||||
rescue NameError => e
|
||||
err = RecipeEvaluationError.new("invalid recipe keyword `#{e.name}'")
|
||||
err.set_backtrace e.backtrace.reject { |l| l =~ /\/producer-core\// }
|
||||
raise err
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user