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:
@@ -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
|
||||
|
8
lib/producer/core/errors.rb
Normal file
8
lib/producer/core/errors.rb
Normal 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
|
@@ -1,8 +1,6 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Recipe
|
||||
RecipeEvaluationError = Class.new(StandardError)
|
||||
|
||||
attr_reader :code, :filepath
|
||||
|
||||
def self.from_file(filepath)
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user