Remove error handling for evaluation errors
This commit is contained in:
parent
0904fa1fc9
commit
a5d9ca26f4
@ -8,18 +8,3 @@ Feature: recipe evaluation
|
|||||||
When I execute the recipe
|
When I execute the recipe
|
||||||
Then the exit status must be 0
|
Then the exit status must be 0
|
||||||
And the output must contain exactly "hello from recipe\n"
|
And the output must contain exactly "hello from recipe\n"
|
||||||
|
|
||||||
Scenario: reports errors when evaluating an invalid recipe
|
|
||||||
Given a recipe with:
|
|
||||||
"""
|
|
||||||
puts 'OK'
|
|
||||||
|
|
||||||
invalid_keyword
|
|
||||||
"""
|
|
||||||
When I execute the recipe
|
|
||||||
Then the exit status must be 70
|
|
||||||
And the output must match:
|
|
||||||
"""
|
|
||||||
\AOK
|
|
||||||
recipe.rb:3:.+invalid recipe keyword `invalid_keyword'
|
|
||||||
"""
|
|
||||||
|
@ -14,18 +14,3 @@ Feature: `source' recipe keyword
|
|||||||
When I execute the recipe
|
When I execute the recipe
|
||||||
Then the exit status must be 0
|
Then the exit status must be 0
|
||||||
And the output must contain "sourced recipe"
|
And the output must contain "sourced recipe"
|
||||||
|
|
||||||
Scenario: reports errors from sourced recipes
|
|
||||||
Given a file named "sourced_recipe.rb" with:
|
|
||||||
"""
|
|
||||||
puts 'OK'
|
|
||||||
invalid_keyword
|
|
||||||
"""
|
|
||||||
When I execute the recipe
|
|
||||||
Then the exit status must be 70
|
|
||||||
Then the output must match:
|
|
||||||
"""
|
|
||||||
\AOK
|
|
||||||
sourced_recipe.rb:2:.+invalid recipe keyword `invalid_keyword'
|
|
||||||
recipe.rb:1:.+
|
|
||||||
"""
|
|
||||||
|
@ -10,17 +10,3 @@ Feature: task evaluation
|
|||||||
When I execute the recipe
|
When I execute the recipe
|
||||||
Then the exit status must be 0
|
Then the exit status must be 0
|
||||||
And the output must contain exactly "hello from recipe\n"
|
And the output must contain exactly "hello from recipe\n"
|
||||||
|
|
||||||
Scenario: reports errors for invalid action calls in a task
|
|
||||||
Given a recipe with:
|
|
||||||
"""
|
|
||||||
task 'some_task' do
|
|
||||||
invalid_action
|
|
||||||
end
|
|
||||||
"""
|
|
||||||
When I execute the recipe
|
|
||||||
Then the exit status must be 70
|
|
||||||
And the output must match:
|
|
||||||
"""
|
|
||||||
\Arecipe.rb:2:.+invalid task action `invalid_action'
|
|
||||||
"""
|
|
||||||
|
@ -12,15 +12,7 @@ module Producer
|
|||||||
|
|
||||||
def run!
|
def run!
|
||||||
check_arguments!
|
check_arguments!
|
||||||
begin
|
recipe.evaluate(env)
|
||||||
recipe.evaluate env
|
|
||||||
rescue RecipeEvaluationError => e
|
|
||||||
backtrace = e.backtrace.reject { |l| l =~ /\/producer-core\// }
|
|
||||||
@stdout.puts [backtrace.shift, e.message].join ': '
|
|
||||||
@stdout.puts backtrace
|
|
||||||
|
|
||||||
exit 70
|
|
||||||
end
|
|
||||||
worker.process recipe.tasks
|
worker.process recipe.tasks
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@ module Producer
|
|||||||
module Core
|
module Core
|
||||||
Error = Class.new(StandardError)
|
Error = Class.new(StandardError)
|
||||||
ConditionNotMetError = Class.new(Error)
|
ConditionNotMetError = Class.new(Error)
|
||||||
RecipeEvaluationError = Class.new(StandardError)
|
|
||||||
TaskEvaluationError = Class.new(RecipeEvaluationError)
|
|
||||||
RemoteCommandExecutionError = Class.new(Error)
|
RemoteCommandExecutionError = Class.new(Error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,10 +18,6 @@ module Producer
|
|||||||
instance_eval &@block
|
instance_eval &@block
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
rescue NameError => e
|
|
||||||
raise RecipeEvaluationError,
|
|
||||||
"invalid recipe keyword `#{e.name}'",
|
|
||||||
e.backtrace
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -23,10 +23,6 @@ module Producer
|
|||||||
@env = env
|
@env = env
|
||||||
instance_eval &@block
|
instance_eval &@block
|
||||||
rescue ConditionNotMetError
|
rescue ConditionNotMetError
|
||||||
rescue NameError => e
|
|
||||||
raise TaskEvaluationError,
|
|
||||||
"invalid task action `#{e.name}'",
|
|
||||||
e.backtrace
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
1
spec/fixtures/recipes/error.rb
vendored
1
spec/fixtures/recipes/error.rb
vendored
@ -1 +0,0 @@
|
|||||||
raise SomeErrorInRecipe, 'some recipe error'
|
|
4
spec/fixtures/recipes/invalid.rb
vendored
4
spec/fixtures/recipes/invalid.rb
vendored
@ -1,4 +0,0 @@
|
|||||||
# this recipe will raise a NameError on line 4 when evaluated by the recipe
|
|
||||||
# DSL.
|
|
||||||
|
|
||||||
invalid_keyword
|
|
@ -37,44 +37,6 @@ module Producer::Core
|
|||||||
expect(cli.worker).to receive(:process).with([:some_task])
|
expect(cli.worker).to receive(:process).with([:some_task])
|
||||||
cli.run!
|
cli.run!
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when recipe evaluation fails' do
|
|
||||||
let(:recipe_file) { fixture_path_for('recipes/invalid.rb') }
|
|
||||||
let(:stdout) { StringIO.new }
|
|
||||||
subject(:cli) { CLI.new(arguments, stdout) }
|
|
||||||
|
|
||||||
context 'when error is known' do
|
|
||||||
it 'exits with a return status of 70' do
|
|
||||||
expect { cli.run! }
|
|
||||||
.to raise_error(SystemExit) { |e|
|
|
||||||
expect(e.status).to eq 70
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'prints the specific error' do
|
|
||||||
trap_exit { cli.run! }
|
|
||||||
expect(stdout.string).to match(/
|
|
||||||
\A
|
|
||||||
#{recipe_file}:4:
|
|
||||||
.+
|
|
||||||
invalid\srecipe\skeyword\s`invalid_keyword'
|
|
||||||
/x)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'excludes producer own source code from the error backtrace' do
|
|
||||||
trap_exit { cli.run! }
|
|
||||||
expect(stdout.string).to_not match /\/producer-core\//
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when error is unknown (unexpected)' do
|
|
||||||
it 'lets the error be' do
|
|
||||||
UnexpectedError = Class.new(StandardError)
|
|
||||||
allow(cli.recipe).to receive(:evaluate).and_raise(UnexpectedError)
|
|
||||||
expect { cli.run! }.to raise_error(UnexpectedError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#check_arguments!' do
|
describe '#check_arguments!' do
|
||||||
|
@ -4,10 +4,6 @@ module Producer::Core
|
|||||||
describe Recipe::DSL do
|
describe Recipe::DSL do
|
||||||
include FixturesHelpers
|
include FixturesHelpers
|
||||||
|
|
||||||
# Specific error thrown in the error fixture recipe, we can't define it in
|
|
||||||
# the recipe, rspec wouldn't know about it.
|
|
||||||
SomeErrorInRecipe = Class.new(RuntimeError)
|
|
||||||
|
|
||||||
let(:code) { proc { } }
|
let(:code) { proc { } }
|
||||||
let(:env) { double('env').as_null_object }
|
let(:env) { double('env').as_null_object }
|
||||||
subject(:dsl) { Recipe::DSL.new &code }
|
subject(:dsl) { Recipe::DSL.new &code }
|
||||||
@ -48,24 +44,6 @@ module Producer::Core
|
|||||||
it 'returns itself' do
|
it 'returns itself' do
|
||||||
expect(dsl.evaluate(env)).to eq dsl
|
expect(dsl.evaluate(env)).to eq dsl
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when recipe is invalid' do
|
|
||||||
let(:filepath) { fixture_path_for 'recipes/error.rb' }
|
|
||||||
let(:recipe) { Recipe.from_file(filepath) }
|
|
||||||
subject(:dsl) { Recipe::DSL.new File.read(filepath) }
|
|
||||||
|
|
||||||
it 'reports the recipe file path in the error' do
|
|
||||||
allow(env).to receive(:current_recipe) { recipe }
|
|
||||||
expect { dsl.evaluate(env) }.to raise_error(SomeErrorInRecipe) { |e|
|
|
||||||
expect(e.backtrace.first).to match /\A#{filepath}/
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'raises a RecipeEvaluationError on NameError' do
|
|
||||||
dsl = Recipe::DSL.new { invalid_keyword }
|
|
||||||
expect { dsl.evaluate(env) }.to raise_error(RecipeEvaluationError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'DSL specific methods' do
|
context 'DSL specific methods' do
|
||||||
@ -88,16 +66,6 @@ module Producer::Core
|
|||||||
it 'sources the recipe given as argument' do
|
it 'sources the recipe given as argument' do
|
||||||
expect { dsl.evaluate(env) }.to throw_symbol :recipe_code
|
expect { dsl.evaluate(env) }.to throw_symbol :recipe_code
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sourced recipe is invalid' do
|
|
||||||
let(:filepath) { fixture_path_for 'recipes/error' }
|
|
||||||
|
|
||||||
it 'reports its file path in the error' do
|
|
||||||
expect { dsl.evaluate(env) }.to raise_error(SomeErrorInRecipe) { |e|
|
|
||||||
expect(e.backtrace.first).to match /\A#{filepath}/
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#target' do
|
describe '#target' do
|
||||||
|
@ -57,14 +57,6 @@ module Producer::Core
|
|||||||
expect(dsl.actions.first.env).to eq env
|
expect(dsl.actions.first.env).to eq env
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when given block is invalid' do
|
|
||||||
it 'raises a TaskEvaluationError on NameError' do
|
|
||||||
dsl = Task::DSL.new { invalid_action }
|
|
||||||
expect { dsl.evaluate(env) }
|
|
||||||
.to raise_error(TaskEvaluationError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#condition' do
|
describe '#condition' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user