diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-07-20 00:06:55 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-07-20 02:52:48 +0300 |
commit | 88dcfe4ff120446de7874ee4e4aedaeff1767203 (patch) | |
tree | 9c228be5382be487a609960dc8935acfe708d100 | |
parent | b566483bda61ae48c58efc40606036276edc3df6 (diff) |
Remove rescue of Gitlab::Git::CommitError at user_merge_to_ref RPC
We've been experiencing transient Gitlab::Git::CommitError's
that were being rescued at gitaly-ruby, specially at
UserMergeToRef RPC.
This commit removes these rescues and also make the error
messages more detailed for further investigation at Sentry.
-rw-r--r-- | changelogs/unreleased/osw-bubble-up-conflicts-error-to-sentry.yml | 5 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/operation_service.rb | 16 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 4 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_spec.rb | 10 |
4 files changed, 28 insertions, 7 deletions
diff --git a/changelogs/unreleased/osw-bubble-up-conflicts-error-to-sentry.yml b/changelogs/unreleased/osw-bubble-up-conflicts-error-to-sentry.yml new file mode 100644 index 000000000..ae09c85f8 --- /dev/null +++ b/changelogs/unreleased/osw-bubble-up-conflicts-error-to-sentry.yml @@ -0,0 +1,5 @@ +--- +title: Remove rescue of Gitlab::Git::CommitError at UserMergeToRef RPC +merge_request: 1372 +author: +type: other diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb index c2869039f..1235a1c01 100644 --- a/ruby/lib/gitlab/git/operation_service.rb +++ b/ruby/lib/gitlab/git/operation_service.rb @@ -110,15 +110,21 @@ module Gitlab # # ref - The target ref path we're committing to. # from_ref - The ref we're taking the HEAD commit from. - def commit_ref(ref, from_ref:) + def commit_ref(ref, source_sha, from_ref:) update_autocrlf_option - repository.write_ref(ref, from_ref.target) + target_sha = from_ref.target + repository.write_ref(ref, target_sha) # Make commit newrev = yield - raise Gitlab::Git::CommitError.new('Failed to create commit') unless newrev + unless newrev + error = "Failed to create merge commit for source_sha #{source_sha} and" \ + " target_sha #{target_sha} at #{ref}" + + raise Gitlab::Git::CommitError.new(error) + end oldrev = from_ref.target @@ -201,8 +207,10 @@ module Gitlab unless status.zero? Gitlab::GitLogger.error("'git update-ref' in #{repository.path}: #{output}") + ref_name = Gitlab::Git.branch_name(ref) || ref + raise Gitlab::Git::CommitError.new( - "Could not update branch #{Gitlab::Git.branch_name(ref)}." \ + "Could not update #{ref_name}." \ " Please refresh and try again." ) end diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index f98886877..ad14b35bb 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -277,14 +277,12 @@ module Gitlab raise InvalidRef unless ref - OperationService.new(user, self).commit_ref(target_ref, from_ref: ref) do + OperationService.new(user, self).commit_ref(target_ref, source_sha, from_ref: ref) do our_commit = ref.target their_commit = source_sha create_merge_commit(user, our_commit, their_commit, message) end - rescue Gitlab::Git::CommitError # when merge_index.conflicts? - nil rescue Rugged::ReferenceError, InvalidRef raise ArgumentError, 'Invalid merge source' end diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb index 8cb8558a6..c7cedbdb7 100644 --- a/ruby/spec/lib/gitlab/git/repository_spec.rb +++ b/ruby/spec/lib/gitlab/git/repository_spec.rb @@ -543,6 +543,16 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength let(:arg_first_parent_ref) {} end end + + context 'when conflicts detected' do + it 'raises Gitlab::Git::CommitError' do + allow(repository.rugged).to receive_message_chain(:merge_commits, :conflicts?) { true } + + expect { repository.merge_to_ref(user, source_sha, arg_branch, target_ref, 'foo', arg_first_parent_ref) } + .to raise_error(Gitlab::Git::CommitError, "Failed to create merge commit for source_sha #{source_sha} and" \ + " target_sha #{branch_head} at #{target_ref}") + end + end end describe '#ff_merge' do |