Skip to content
代码片段 群组 项目
提交 dc112cfc 编辑于 作者: Tetiana Chupryna's avatar Tetiana Chupryna
浏览文件

Merge branch 'georgekoltsov/dont-fail-project-export-when-exporting-diffs' into 'master'

No related branches found
No related tags found
无相关合并请求
......@@ -25,6 +25,10 @@ def utf8_diff
return '' if fetched_diff.blank?
encode_utf8(fetched_diff) if fetched_diff.respond_to?(:encoding)
rescue StandardError => e
log_exception('Failed fetching merge request diff', e)
''
end
def diff
......@@ -75,15 +79,19 @@ def diff_export
content
rescue StandardError => e
log_exception('Cached external diff export failed', e)
diff
end
def log_exception(message, exception)
log_payload = {
message: 'Cached external diff export failed',
message: message,
merge_request_diff_file_id: id,
merge_request_diff_id: merge_request_diff&.id
}
Gitlab::ExceptionLogFormatter.format!(e, log_payload)
Gitlab::ExceptionLogFormatter.format!(exception, log_payload)
Gitlab::AppLogger.warn(log_payload)
diff
end
end
......@@ -220,5 +220,25 @@
file.utf8_diff
end
end
context 'when exception is raised' do
it 'logs exception and returns an empty string' do
allow(file).to receive(:diff).and_raise(StandardError, 'Error!')
expect(Gitlab::AppLogger)
.to receive(:warn)
.with(
a_hash_including(
:message => 'Failed fetching merge request diff',
:merge_request_diff_file_id => file.id,
:merge_request_diff_id => file.merge_request_diff.id,
'exception.class' => 'StandardError',
'exception.message' => 'Error!'
)
)
expect(file.utf8_diff).to eq('')
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册