diff options
author | Luke Duncalfe <lduncalfe@eml.cc> | 2019-04-09 10:55:07 +1200 |
---|---|---|
committer | Luke Duncalfe <lduncalfe@eml.cc> | 2019-04-09 10:57:04 +1200 |
commit | b5bcf80c9a7470ac36bdbefcb8056beff67712ae (patch) | |
tree | 8bc00389e054d0aa68d659f9d117b8777f434c44 | |
parent | 3c40c98e263328ceb11a008dbec108362e727dbc (diff) | |
download | gitlab-ce-43263-git-push-option-to-create-mr.tar.gz |
Update service to handle unexpected exceptions43263-git-push-option-to-create-mr
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 } |