Fix error formatting in debug mode
Backtrace filtering was only disabled for exception cause, this change ensure no backtrace filtering at all in debug mode. * Prevent main exception filtering when debug mode is enabled; * Test when exception cause must be displayed; * Test how exception cause must be displayed.
This commit is contained in:
parent
b93e5717ce
commit
1ccd95b80f
@ -1,11 +1,13 @@
|
||||
Feature: CLI debug option
|
||||
|
||||
Background:
|
||||
Given a recipe with:
|
||||
"""
|
||||
task(:trigger_error) { fail 'some error' }
|
||||
"""
|
||||
|
||||
Scenario: reports recipe errors
|
||||
Scenario: reports recipe errors with their cause
|
||||
Given a recipe with an error
|
||||
When I execute the recipe with option -d
|
||||
Then the output must match /\ARuntimeError:.*\n\ncause:\nRuntimeError:/
|
||||
|
||||
Scenario: does not exclude anything from backtrace
|
||||
Given a recipe using a remote
|
||||
When I execute the recipe on unknown remote target with option -d
|
||||
Then the output must contain "producer-core"
|
||||
And the output must contain "net-ssh"
|
||||
And the output must contain ruby lib directory
|
||||
|
@ -26,6 +26,10 @@ Then /^the error output must contain exactly "([^"]+)"$/ do |content|
|
||||
assert_exact_output content, all_stderr
|
||||
end
|
||||
|
||||
Then /^the output must contain ruby lib directory$/ do
|
||||
assert_partial_output RbConfig::CONFIG['rubylibdir'], all_output
|
||||
end
|
||||
|
||||
Then /^the output must not contain ruby lib directory$/ do
|
||||
assert_no_partial_output RbConfig::CONFIG['rubylibdir'], all_output
|
||||
end
|
||||
|
@ -27,6 +27,11 @@ When /^I execute the recipe on unknown remote target$/ do
|
||||
assert_matching_output '\ASocketError', all_output
|
||||
end
|
||||
|
||||
When /^I execute the recipe on unknown remote target with option (-.+)$/ do |option|
|
||||
run_simple "producer recipe.rb #{option} -t #unknown_host.test", false
|
||||
assert_matching_output '\ASocketError', all_output
|
||||
end
|
||||
|
||||
When /^I successfully execute the recipe$/ do
|
||||
step 'I execute the recipe'
|
||||
assert_exit_status 0
|
||||
|
@ -18,7 +18,7 @@ module Producer
|
||||
end
|
||||
|
||||
def format(exception)
|
||||
lines = format_exception exception
|
||||
lines = format_exception exception, filter: !debug?
|
||||
|
||||
if debug? && exception.cause
|
||||
lines << ''
|
||||
|
@ -25,9 +25,10 @@ module Producer
|
||||
describe '#format' do
|
||||
let(:rubylibdir) { RbConfig::CONFIG['rubylibdir'] }
|
||||
let(:bt) { %W[backtrace /producer-core /net-ssh #{rubylibdir}] }
|
||||
let(:exception) { RuntimeError.new('some exception').tap { |o| o.set_backtrace bt } }
|
||||
|
||||
def exception
|
||||
begin fail 'original exception' rescue fail 'some exception' end
|
||||
def exception_with_cause
|
||||
begin fail 'exception cause' rescue fail 'some exception' end
|
||||
rescue => e
|
||||
e.tap { |o| o.set_backtrace bt }
|
||||
end
|
||||
@ -41,7 +42,6 @@ module Producer
|
||||
expect(formatter.format exception).to match /^\s+backtrace$/
|
||||
end
|
||||
|
||||
context 'filtering' do
|
||||
it 'excludes producer code from the backtrace' do
|
||||
expect(formatter.format exception).not_to include 'producer-core'
|
||||
end
|
||||
@ -54,12 +54,30 @@ module Producer
|
||||
expect(formatter.format exception).not_to include rubylibdir
|
||||
end
|
||||
|
||||
context 'when exception has a cause' do
|
||||
it 'does not include the cause' do
|
||||
expect(formatter.format exception_with_cause)
|
||||
.not_to include 'exception cause'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when debug is enabled' do
|
||||
let(:debug) { true }
|
||||
|
||||
it 'does not exclude producer code from the backtrace' do
|
||||
it 'does not filter the backtrace' do
|
||||
expect(formatter.format exception).to include 'producer-core'
|
||||
end
|
||||
|
||||
context 'when exception has a cause' do
|
||||
it 'includes the exception cause' do
|
||||
expect(formatter.format exception_with_cause)
|
||||
.to include 'exception cause'
|
||||
end
|
||||
|
||||
it 'formats the cause' do
|
||||
expect(formatter.format exception_with_cause)
|
||||
.to match /^cause:\nRuntimeError: exception cause/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user