1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-02-01 01:37:12 +00:00

Do not rescue exceptions on Proc normalization

Rescuing exceptions here would mask errors and make debugging realy hard
when setting e.g. default fields.
This commit is contained in:
Holger Just 2017-10-08 21:35:40 +02:00
parent b64823170f
commit 2d0f47a813
2 changed files with 23 additions and 10 deletions

View File

@ -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

View File

@ -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