From 2d0f47a813e51f616367b91c2fea59420b097e49 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sun, 8 Oct 2017 21:35:40 +0200 Subject: [PATCH] Do not rescue exceptions on Proc normalization Rescuing exceptions here would mask errors and make debugging realy hard when setting e.g. default fields. --- lib/rackstash/fields/abstract_collection.rb | 2 -- .../fields/abstract_collection_spec.rb | 31 ++++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/rackstash/fields/abstract_collection.rb b/lib/rackstash/fields/abstract_collection.rb index 1c70261..b2cbd48 100644 --- a/lib/rackstash/fields/abstract_collection.rb +++ b/lib/rackstash/fields/abstract_collection.rb @@ -108,8 +108,6 @@ module Rackstash return value.call if scope.nil? value.arity == 0 ? scope.instance_exec(&value) : value.call(scope) - rescue - value.inspect end # Note: You should never mutate an array or hash returned by normalize diff --git a/spec/rackstash/fields/abstract_collection_spec.rb b/spec/rackstash/fields/abstract_collection_spec.rb index 611b6be..e8a41bc 100644 --- a/spec/rackstash/fields/abstract_collection_spec.rb +++ b/spec/rackstash/fields/abstract_collection_spec.rb @@ -503,15 +503,30 @@ describe Rackstash::Fields::AbstractCollection do expect(normalize(outer)).to eql 'return' end - it 'returns the inspected proc on errors' do - error = -> { raise 'Oh, no!' } - expected_arguments = ->(_arg1, _args, _arg3) { 'cherio' } - ok = -> { :ok } - outer = -> { [ok, error, expected_arguments] } + it 'stops on error and raises' do + called = Hash.new(false) - expect(normalize(outer)) - .to be_a(Rackstash::Fields::Array) - .and contain_exactly('ok', error.inspect, expected_arguments.inspect) + ok = -> { + called[:ok] = true + :ok + } + + error = -> { + called[:error] = true + raise 'Oh, no!' + } + + ignored = ->() { + called[:ignored] = true + 'cherio' + } + + proc = -> { [ok, error, ignored] } + + expect { normalize(proc) }.to raise_error('Oh, no!') + expect(called[:ok]).to be true + expect(called[:error]).to be true + expect(called[:ignored]).to be false end end