Commit 649c7ca8 authored by Stan Hu's avatar Stan Hu

Log exceptions in Commits::CreateService

If an exception is caught in Commits::CreateService, the return value is
handled by the caller, but there is currently no way for an admin to
know what happened because there are many possibilities (e.g. validation
error, pre-receive error, etc.).

For better observability, this change logs the exception but does not
report it to Sentry because that could create noise (e.g. repository
size limits exceeded is not a bug in the system).

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/220168
parent e7631cb4
......@@ -30,12 +30,14 @@ module Commits
success(result: new_commit)
rescue ChangeError => ex
Gitlab::ErrorTracking.log_exception(ex)
error(ex.message, pass_back: { error_code: ex.error_code })
rescue ValidationError,
Gitlab::Git::Index::IndexError,
Gitlab::Git::CommitError,
Gitlab::Git::PreReceiveError,
Gitlab::Git::CommandError => ex
Gitlab::ErrorTracking.log_exception(ex)
error(ex.message)
end
......
......@@ -24,6 +24,8 @@ RSpec.describe Commits::CreateService do
subject(:result) { service.execute }
it 'raises an error if the repositoy exceeds the size limit' do
expect(Gitlab::ErrorTracking).to receive(:log_exception)
.with(instance_of(Commits::CreateService::ValidationError)).and_call_original
expect(result[:status]).to be(:error)
expect(result[:message]).to eq('Your changes could not be committed, because this repository has exceeded its size limit of 1 Byte by 1 Byte')
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