Commit 0b02f56c authored by Sean McGivern's avatar Sean McGivern

Merge branch '195625-markup_helper-to-handle-StandardError-and-add-logging' into 'master'

Allow #markup_unsafe to handle StandardError and notify exception

See merge request gitlab-org/gitlab!22550
parents 9d135aa7 ba7eccf7
......@@ -154,7 +154,9 @@ module MarkupHelper
else
other_markup_unsafe(file_name, text, context)
end
rescue RuntimeError
rescue StandardError => e
Gitlab::ErrorTracking.track_exception(e, project_id: @project&.id, file_name: file_name, context: context)
simple_format(text)
end
......
......@@ -357,10 +357,10 @@ describe MarkupHelper do
describe '#markup_unsafe' do
subject { helper.markup_unsafe(file_name, text, context) }
let_it_be(:project_base) { create(:project, :repository) }
let_it_be(:context) { { project: project_base } }
let(:file_name) { 'foo.bar' }
let(:text) { 'Noël' }
let(:project_base) { build(:project, :repository) }
let(:context) { { project: project_base } }
context 'when text is missing' do
let(:text) { nil }
......@@ -383,12 +383,21 @@ describe MarkupHelper do
context 'when renderer returns an error' do
before do
allow(Banzai).to receive(:render).and_raise("An error")
allow(Banzai).to receive(:render).and_raise(StandardError, "An error")
end
it 'returns html (rendered by ActionView:TextHelper)' do
is_expected.to eq('<p>Noël</p>')
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
instance_of(StandardError),
project_id: project.id, file_name: 'foo.md', context: context
)
subject
end
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