Commit 4cd4740d authored by Jasper Maes's avatar Jasper Maes

Rails5 fix NoMethodError: undefined method 'message' for nil:NilClass

parent 2190828c
---
title: 'Rails5 fix NoMethodError: undefined method ''message'' for nil:NilClass'
merge_request: 6507
author: Jasper Maes
type: fixed
...@@ -12,6 +12,41 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do ...@@ -12,6 +12,41 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do
RequestStore.delete(described_class::CACHE_KEY) RequestStore.delete(described_class::CACHE_KEY)
end end
def raise_and_wrap(wrapper, original)
raise original
rescue original.class
raise wrapper.new('boop')
end
def wrapped_exception(wrapper, original)
if Gitlab.rails5?
begin
raise_and_wrap(wrapper, original.new)
rescue wrapper => error
error
end
else
wrapper.new('boop', original.new)
end
end
def twice_wrapped_exception(top, middle, original)
if Gitlab.rails5?
begin
begin
raise_and_wrap(middle, original.new)
rescue middle => middle_error
raise_and_wrap(top, middle_error)
end
rescue top => top_error
top_error
end
else
middle_error = middle.new('boop', original.new)
top.new('boop', middle_error)
end
end
describe '#read' do describe '#read' do
let(:conflict_error) { Class.new(RuntimeError) } let(:conflict_error) { Class.new(RuntimeError) }
...@@ -227,23 +262,19 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do ...@@ -227,23 +262,19 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do
end end
it 'returns true for a wrapped connection error' do it 'returns true for a wrapped connection error' do
original = NotImplementedError.new wrapped = wrapped_exception(ActiveRecord::StatementInvalid, NotImplementedError)
wrapped = ActiveRecord::StatementInvalid.new('boop', original)
expect(lb.connection_error?(wrapped)).to eq(true) expect(lb.connection_error?(wrapped)).to eq(true)
end end
it 'returns true for a wrapped connection error from a view' do it 'returns true for a wrapped connection error from a view' do
original = NotImplementedError.new wrapped = wrapped_exception(ActionView::Template::Error, NotImplementedError)
wrapped = ActionView::Template::Error.new('boop', original)
expect(lb.connection_error?(wrapped)).to eq(true) expect(lb.connection_error?(wrapped)).to eq(true)
end end
it 'returns true for deeply wrapped/nested errors' do it 'returns true for deeply wrapped/nested errors' do
original = NotImplementedError.new top = twice_wrapped_exception(ActionView::Template::Error, ActiveRecord::StatementInvalid, NotImplementedError)
middle = ActiveRecord::StatementInvalid.new('boop', original)
top = ActionView::Template::Error.new('boop', middle)
expect(lb.connection_error?(top)).to eq(true) expect(lb.connection_error?(top)).to eq(true)
end end
...@@ -276,7 +307,7 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do ...@@ -276,7 +307,7 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do
end end
it 'returns true for a wrapped error' do it 'returns true for a wrapped error' do
wrapped = ActionView::Template::Error.new('boop', conflict_error.new) wrapped = wrapped_exception(ActionView::Template::Error, conflict_error)
expect(lb.serialization_failure?(wrapped)).to eq(true) expect(lb.serialization_failure?(wrapped)).to eq(true)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment