Commit ce9924ad authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fj-improve-snippet-log-message' into 'master'

Improve snippet log message

See merge request gitlab-org/gitlab!47907
parents fb725fd6 7b6128a0
......@@ -56,7 +56,7 @@ module Snippets
snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
log_error(e.message)
Gitlab::ErrorTracking.log_exception(e, service: 'Snippets::CreateService')
# If the commit action failed we need to remove the repository if exists
delete_repository(@snippet) if @snippet.repository_exists?
......
......@@ -74,7 +74,7 @@ module Snippets
add_snippet_repository_error(snippet: snippet, error: e)
log_error(e.message)
Gitlab::ErrorTracking.log_exception(e, service: 'Snippets::UpdateService')
# If the commit action failed we remove it because
# we don't want to leave empty repositories
......
......@@ -147,9 +147,11 @@ RSpec.describe Snippets::CreateService do
end
context 'when the commit action fails' do
let(:error) { SnippetRepository::CommitError.new('foobar') }
before do
allow_next_instance_of(SnippetRepository) do |instance|
allow(instance).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError.new('foobar'))
allow(instance).to receive(:multi_files_action).and_raise(error)
end
end
......@@ -172,7 +174,7 @@ RSpec.describe Snippets::CreateService do
end
it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with('foobar')
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(error, service: 'Snippets::CreateService')
subject
end
......
......@@ -277,14 +277,14 @@ RSpec.describe Snippets::UpdateService do
end
context 'when an error is raised' do
let(:error_message) { 'foobar' }
let(:error) { SnippetRepository::CommitError.new('foobar') }
before do
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, error_message)
allow(snippet.snippet_repository).to receive(:multi_files_action).and_raise(error)
end
it 'logs the error' do
expect(Gitlab::AppLogger).to receive(:error).with(error_message)
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(error, service: 'Snippets::UpdateService')
subject
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