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
RequestStore.delete(described_class::CACHE_KEY)
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
let(:conflict_error) { Class.new(RuntimeError) }
......@@ -227,23 +262,19 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do
end
it 'returns true for a wrapped connection error' do
original = NotImplementedError.new
wrapped = ActiveRecord::StatementInvalid.new('boop', original)
wrapped = wrapped_exception(ActiveRecord::StatementInvalid, NotImplementedError)
expect(lb.connection_error?(wrapped)).to eq(true)
end
it 'returns true for a wrapped connection error from a view' do
original = NotImplementedError.new
wrapped = ActionView::Template::Error.new('boop', original)
wrapped = wrapped_exception(ActionView::Template::Error, NotImplementedError)
expect(lb.connection_error?(wrapped)).to eq(true)
end
it 'returns true for deeply wrapped/nested errors' do
original = NotImplementedError.new
middle = ActiveRecord::StatementInvalid.new('boop', original)
top = ActionView::Template::Error.new('boop', middle)
top = twice_wrapped_exception(ActionView::Template::Error, ActiveRecord::StatementInvalid, NotImplementedError)
expect(lb.connection_error?(top)).to eq(true)
end
......@@ -276,7 +307,7 @@ describe Gitlab::Database::LoadBalancing::LoadBalancer do
end
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)
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