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:
parent
b64823170f
commit
2d0f47a813
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user