Commit 30ffa71e authored by Stan Hu's avatar Stan Hu

Merge branch 'log_pre_receive_on_create_branch' into 'master'

Log raw pre receive error for create branch service

See merge request gitlab-org/gitlab!38749
parents 32f9115a 9dab7892
......@@ -16,8 +16,9 @@ module Branches
else
error("Invalid reference name: #{ref}")
end
rescue Gitlab::Git::PreReceiveError => ex
error(ex.message)
rescue Gitlab::Git::PreReceiveError => e
Gitlab::ErrorTracking.track_exception(e, pre_receive_message: e.raw_message, branch_name: branch_name, ref: ref)
error(e.message)
end
def success(branch)
......
---
title: Log raw pre receive error for create branch service
merge_request: 38749
author:
type: other
......@@ -44,5 +44,25 @@ RSpec.describe Branches::CreateService do
expect(result[:message]).to eq('Invalid reference name: unknown')
end
end
it 'logs and returns an error if there is a PreReceiveError exception' do
error_message = 'pre receive error'
raw_message = "GitLab: #{error_message}"
pre_receive_error = Gitlab::Git::PreReceiveError.new(raw_message)
allow(project.repository).to receive(:add_branch).and_raise(pre_receive_error)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
pre_receive_error,
pre_receive_message: raw_message,
branch_name: 'new-feature',
ref: 'unknown'
)
result = service.execute('new-feature', 'unknown')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq(error_message)
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