Fix backtrace filtering for producer

This commit is contained in:
Thibault Jouan 2015-04-03 21:52:27 +00:00
parent dc561de047
commit 0da47a0acb
3 changed files with 11 additions and 8 deletions

View File

@ -16,6 +16,11 @@ Feature: CLI error reporting
When I execute the recipe When I execute the recipe
Then the output must match /^\s+recipe\.rb \(recipe\)\n\s+recipe\.rb:/ Then the output must match /^\s+recipe\.rb \(recipe\)\n\s+recipe\.rb:/
Scenario: excludes producer from backtrace
Given a recipe using a remote
When I execute the recipe on unknown remote target
Then the output must not contain "producer-core"
Scenario: excludes net-ssh from backtrace Scenario: excludes net-ssh from backtrace
Given a recipe using a remote Given a recipe using a remote
When I execute the recipe on unknown remote target When I execute the recipe on unknown remote target

View File

@ -2,7 +2,7 @@ module Producer
module Core module Core
class ErrorFormatter class ErrorFormatter
FILTERS = [ FILTERS = [
/\/producer-\w+\/(?:bin|lib)\//, /\/producer-\w+/,
/\/net-ssh/, /\/net-ssh/,
/\/net-sftp/ /\/net-sftp/
].freeze ].freeze

View File

@ -23,10 +23,12 @@ module Producer
end end
describe '#format' do describe '#format' do
let(:bt) { %W[backtrace /producer-core /net-ssh] }
def exception def exception
begin fail 'original exception' rescue fail 'some exception' end begin fail 'original exception' rescue fail 'some exception' end
rescue rescue => e
$!.tap { |o| o.set_backtrace %w[back trace] } e.tap { |o| o.set_backtrace bt }
end end
it 'formats the message' do it 'formats the message' do
@ -35,14 +37,10 @@ module Producer
end end
it 'indents the backtrace' do it 'indents the backtrace' do
expect(formatter.format exception).to match /^\s+back$/ expect(formatter.format exception).to match /^\s+backtrace$/
end end
context 'filtering' do context 'filtering' do
let(:bt) { %w[back trace producer-core net-ssh net-sftp] }
before { exception.set_backtrace bt }
it 'excludes producer code from the backtrace' do it 'excludes producer code from the backtrace' do
expect(formatter.format exception).not_to include 'producer-core' expect(formatter.format exception).not_to include 'producer-core'
end end