Improve error reporting during recipe evaluation

* Report invalid action usages from tasks;
* Implement backtrace cleaning in CLI;
* Extract error class declarations in a new errors file;
* Replace raise with fail keyword in task DSL class.
This commit is contained in:
Thibault Jouan
2013-08-01 17:15:11 +00:00
parent 836f9ffc29
commit c4fc9828db
10 changed files with 56 additions and 17 deletions

View File

@@ -24,9 +24,10 @@ module Producer
env = Env.new(recipe)
begin
recipe.evaluate env
rescue Recipe::RecipeEvaluationError => e
@stdout.puts [e.backtrace.shift, e.message].join ': '
@stdout.puts e.backtrace
rescue RecipeEvaluationError => e
backtrace = e.backtrace.reject { |l| l =~ /\/producer-core\// }
@stdout.puts [backtrace.shift, e.message].join ': '
@stdout.puts backtrace
exit 70
end

View File

@@ -0,0 +1,8 @@
module Producer
module Core
Error = Class.new(StandardError)
ConditionNotMetError = Class.new(Error)
RecipeEvaluationError = Class.new(StandardError)
TaskEvaluationError = Class.new(RecipeEvaluationError)
end
end

View File

@@ -1,8 +1,6 @@
module Producer
module Core
class Recipe
RecipeEvaluationError = Class.new(StandardError)
attr_reader :code, :filepath
def self.from_file(filepath)

View File

@@ -18,9 +18,9 @@ module Producer
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
raise RecipeEvaluationError,
"invalid recipe keyword `#{e.name}'",
e.backtrace
end
private

View File

@@ -2,8 +2,6 @@ module Producer
module Core
class Task
class DSL
ConditionNotMetError = Class.new(StandardError)
def initialize(&block)
@block = block
end
@@ -11,10 +9,14 @@ module Producer
def evaluate(env)
instance_eval &@block
rescue ConditionNotMetError
rescue NameError => e
raise TaskEvaluationError,
"invalid task action `#{e.name}'",
e.backtrace
end
def condition(&block)
raise ConditionNotMetError unless block.call
fail ConditionNotMetError unless block.call
end
end
end