From 0da47a0acb4cab1b5b10ce78c497385fffb30d19 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Fri, 3 Apr 2015 21:52:27 +0000 Subject: [PATCH] Fix backtrace filtering for producer --- features/cli/error_reporting.feature | 5 +++++ lib/producer/core/error_formatter.rb | 2 +- spec/producer/core/error_formatter_spec.rb | 12 +++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/features/cli/error_reporting.feature b/features/cli/error_reporting.feature index 01ddb2d..ab69d0f 100644 --- a/features/cli/error_reporting.feature +++ b/features/cli/error_reporting.feature @@ -16,6 +16,11 @@ Feature: CLI error reporting When I execute the recipe 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 Given a recipe using a remote When I execute the recipe on unknown remote target diff --git a/lib/producer/core/error_formatter.rb b/lib/producer/core/error_formatter.rb index 5ac1e05..08785ff 100644 --- a/lib/producer/core/error_formatter.rb +++ b/lib/producer/core/error_formatter.rb @@ -2,7 +2,7 @@ module Producer module Core class ErrorFormatter FILTERS = [ - /\/producer-\w+\/(?:bin|lib)\//, + /\/producer-\w+/, /\/net-ssh/, /\/net-sftp/ ].freeze diff --git a/spec/producer/core/error_formatter_spec.rb b/spec/producer/core/error_formatter_spec.rb index 268c61c..447370f 100644 --- a/spec/producer/core/error_formatter_spec.rb +++ b/spec/producer/core/error_formatter_spec.rb @@ -23,10 +23,12 @@ module Producer end describe '#format' do + let(:bt) { %W[backtrace /producer-core /net-ssh] } + def exception begin fail 'original exception' rescue fail 'some exception' end - rescue - $!.tap { |o| o.set_backtrace %w[back trace] } + rescue => e + e.tap { |o| o.set_backtrace bt } end it 'formats the message' do @@ -35,14 +37,10 @@ module Producer end it 'indents the backtrace' do - expect(formatter.format exception).to match /^\s+back$/ + expect(formatter.format exception).to match /^\s+backtrace$/ end 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 expect(formatter.format exception).not_to include 'producer-core' end