Remove error handling for evaluation errors

This commit is contained in:
Thibault Jouan 2013-08-13 00:11:53 +00:00
parent 0904fa1fc9
commit a5d9ca26f4
12 changed files with 1 additions and 146 deletions

View File

@ -8,18 +8,3 @@ Feature: recipe evaluation
When I execute the recipe
Then the exit status must be 0
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'
"""

View File

@ -14,18 +14,3 @@ Feature: `source' recipe keyword
When I execute the recipe
Then the exit status must be 0
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:.+
"""

View File

@ -10,17 +10,3 @@ Feature: task evaluation
When I execute the recipe
Then the exit status must be 0
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'
"""

View File

@ -12,15 +12,7 @@ module Producer
def run!
check_arguments!
begin
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
recipe.evaluate(env)
worker.process recipe.tasks
end

View File

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

View File

@ -18,10 +18,6 @@ module Producer
instance_eval &@block
end
self
rescue NameError => e
raise RecipeEvaluationError,
"invalid recipe keyword `#{e.name}'",
e.backtrace
end
private

View File

@ -23,10 +23,6 @@ module Producer
@env = env
instance_eval &@block
rescue ConditionNotMetError
rescue NameError => e
raise TaskEvaluationError,
"invalid task action `#{e.name}'",
e.backtrace
end
private

View File

@ -1 +0,0 @@
raise SomeErrorInRecipe, 'some recipe error'

View File

@ -1,4 +0,0 @@
# this recipe will raise a NameError on line 4 when evaluated by the recipe
# DSL.
invalid_keyword

View File

@ -37,44 +37,6 @@ module Producer::Core
expect(cli.worker).to receive(:process).with([:some_task])
cli.run!
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
describe '#check_arguments!' do

View File

@ -4,10 +4,6 @@ module Producer::Core
describe Recipe::DSL do
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(:env) { double('env').as_null_object }
subject(:dsl) { Recipe::DSL.new &code }
@ -48,24 +44,6 @@ module Producer::Core
it 'returns itself' do
expect(dsl.evaluate(env)).to eq dsl
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
context 'DSL specific methods' do
@ -88,16 +66,6 @@ module Producer::Core
it 'sources the recipe given as argument' do
expect { dsl.evaluate(env) }.to throw_symbol :recipe_code
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
describe '#target' do

View File

@ -57,14 +57,6 @@ module Producer::Core
expect(dsl.actions.first.env).to eq env
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
describe '#condition' do