diff options
author | Luke Duncalfe <lduncalfe@eml.cc> | 2019-04-09 10:55:07 +1200 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-04-10 10:43:31 +0100 |
commit | af15600bc007346bd685927f5aeb29828f7b42e3 (patch) | |
tree | dcb4f842ca2aeb771999a85fd5bc25a75c6c8c3d | |
parent | 80a3ce59fa42641ccfc079c3c648605674c2b543 (diff) | |
download | gitlab-ce-43263-git-push-option-to-create-mr-11-10.tar.gz |
Update service to handle unexpected exceptions43263-git-push-option-to-create-mr-11-10
This will ensure that now and in the future, PushOptionsHandlerService
will not cause the post_receive API endpoint from running other code if
something causes an unknown exception.
-rw-r--r-- | app/services/merge_requests/push_options_handler_service.rb | 3 | ||||
-rw-r--r-- | spec/services/merge_requests/push_options_handler_service_spec.rb | 26 |
2 files changed, 29 insertions, 0 deletions
diff --git a/app/services/merge_requests/push_options_handler_service.rb b/app/services/merge_requests/push_options_handler_service.rb index 610d1db0506..d92eb0a68c3 100644 --- a/app/services/merge_requests/push_options_handler_service.rb +++ b/app/services/merge_requests/push_options_handler_service.rb @@ -24,6 +24,9 @@ module MergeRequests execute_for_branch(branch) rescue Gitlab::Access::AccessDeniedError errors << 'User access was denied' + rescue StandardError => e + Gitlab::AppLogger.error(e) + errors << 'An unknown error occurred' end self diff --git a/spec/services/merge_requests/push_options_handler_service_spec.rb b/spec/services/merge_requests/push_options_handler_service_spec.rb index af52feef24d..686b4b49f24 100644 --- a/spec/services/merge_requests/push_options_handler_service_spec.rb +++ b/spec/services/merge_requests/push_options_handler_service_spec.rb @@ -334,6 +334,32 @@ describe MergeRequests::PushOptionsHandlerService do end end + describe 'handling unexpected exceptions' do + let(:push_options) { { create: true } } + let(:changes) { new_branch_changes } + let(:exception) { StandardError.new('My standard error') } + + def run_service_with_exception + allow_any_instance_of( + MergeRequests::BuildService + ).to receive(:execute).and_raise(exception) + + service.execute + end + + it 'records an error' do + run_service_with_exception + + expect(service.errors).to eq(['An unknown error occurred']) + end + + it 'writes to Gitlab::AppLogger' do + expect(Gitlab::AppLogger).to receive(:error).with(exception) + + run_service_with_exception + end + end + describe 'when target is not a valid branch name' do let(:push_options) { { create: true, target: 'my-branch' } } let(:changes) { new_branch_changes } |