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

@@ -89,11 +89,13 @@ module Producer::Core
}
end
it 'prints the error' do
begin
cli.evaluate_recipe_file
rescue SystemExit
end
def trap_exit
yield
rescue SystemExit
end
it 'prints the specific error' do
trap_exit { cli.evaluate_recipe_file }
expect(stdout.string).to match(/
\A
#{recipe_file}:4:
@@ -101,6 +103,11 @@ module Producer::Core
invalid\srecipe\skeyword\s`invalid_keyword'
/x)
end
it 'excludes producer own source code from the error backtrace' do
trap_exit { cli.evaluate_recipe_file }
expect(stdout.string).to_not match /\/producer-core\//
end
end
end
end

View File

@@ -50,7 +50,7 @@ module Producer::Core
it 'raises a RecipeEvaluationError on NameError' do
dsl = Recipe::DSL.new { invalid_keyword }
expect { dsl.evaluate(env) }.to raise_error(Recipe::RecipeEvaluationError)
expect { dsl.evaluate(env) }.to raise_error(RecipeEvaluationError)
end
end
end

View File

@@ -12,6 +12,14 @@ module Producer::Core
expect { dsl.evaluate(env) }
.to raise_error(RuntimeError, 'error from task')
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