From a5d9ca26f443432e034816ad461d811314baec96 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 13 Aug 2013 00:11:53 +0000 Subject: [PATCH] Remove error handling for evaluation errors --- features/recipes/evaluation.feature | 15 ----------- features/recipes/source.feature | 15 ----------- features/tasks/evaluation.feature | 14 ---------- lib/producer/core/cli.rb | 10 +------ lib/producer/core/errors.rb | 2 -- lib/producer/core/recipe/dsl.rb | 4 --- lib/producer/core/task/dsl.rb | 4 --- spec/fixtures/recipes/error.rb | 1 - spec/fixtures/recipes/invalid.rb | 4 --- spec/producer/core/cli_spec.rb | 38 --------------------------- spec/producer/core/recipe/dsl_spec.rb | 32 ---------------------- spec/producer/core/task/dsl_spec.rb | 8 ------ 12 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 spec/fixtures/recipes/error.rb delete mode 100644 spec/fixtures/recipes/invalid.rb diff --git a/features/recipes/evaluation.feature b/features/recipes/evaluation.feature index d66c84f..ae8b178 100644 --- a/features/recipes/evaluation.feature +++ b/features/recipes/evaluation.feature @@ -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' - """ diff --git a/features/recipes/source.feature b/features/recipes/source.feature index 7500292..a02abc0 100644 --- a/features/recipes/source.feature +++ b/features/recipes/source.feature @@ -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:.+ - """ diff --git a/features/tasks/evaluation.feature b/features/tasks/evaluation.feature index 111d089..51f0b6b 100644 --- a/features/tasks/evaluation.feature +++ b/features/tasks/evaluation.feature @@ -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' - """ diff --git a/lib/producer/core/cli.rb b/lib/producer/core/cli.rb index 7188ae4..7bd9ddc 100644 --- a/lib/producer/core/cli.rb +++ b/lib/producer/core/cli.rb @@ -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 diff --git a/lib/producer/core/errors.rb b/lib/producer/core/errors.rb index 901946a..6710882 100644 --- a/lib/producer/core/errors.rb +++ b/lib/producer/core/errors.rb @@ -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 diff --git a/lib/producer/core/recipe/dsl.rb b/lib/producer/core/recipe/dsl.rb index c57d490..b0a7b09 100644 --- a/lib/producer/core/recipe/dsl.rb +++ b/lib/producer/core/recipe/dsl.rb @@ -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 diff --git a/lib/producer/core/task/dsl.rb b/lib/producer/core/task/dsl.rb index bc84580..2987ef7 100644 --- a/lib/producer/core/task/dsl.rb +++ b/lib/producer/core/task/dsl.rb @@ -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 diff --git a/spec/fixtures/recipes/error.rb b/spec/fixtures/recipes/error.rb deleted file mode 100644 index 6ba9843..0000000 --- a/spec/fixtures/recipes/error.rb +++ /dev/null @@ -1 +0,0 @@ -raise SomeErrorInRecipe, 'some recipe error' diff --git a/spec/fixtures/recipes/invalid.rb b/spec/fixtures/recipes/invalid.rb deleted file mode 100644 index f454281..0000000 --- a/spec/fixtures/recipes/invalid.rb +++ /dev/null @@ -1,4 +0,0 @@ -# this recipe will raise a NameError on line 4 when evaluated by the recipe -# DSL. - -invalid_keyword diff --git a/spec/producer/core/cli_spec.rb b/spec/producer/core/cli_spec.rb index 12100c3..895a159 100644 --- a/spec/producer/core/cli_spec.rb +++ b/spec/producer/core/cli_spec.rb @@ -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 diff --git a/spec/producer/core/recipe/dsl_spec.rb b/spec/producer/core/recipe/dsl_spec.rb index af3a317..fe51f05 100644 --- a/spec/producer/core/recipe/dsl_spec.rb +++ b/spec/producer/core/recipe/dsl_spec.rb @@ -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 diff --git a/spec/producer/core/task/dsl_spec.rb b/spec/producer/core/task/dsl_spec.rb index 4b66aba..dbf9f65 100644 --- a/spec/producer/core/task/dsl_spec.rb +++ b/spec/producer/core/task/dsl_spec.rb @@ -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