Cleanup after adding rubocop: BanCatchThrow
In !25990 (merged) we add Cop: BanCatchThrow
and add exceptions for a bunch of cases. This issue is to track the effort to remove those exceptions from the codebase.
Here's the list as of today:
Offenses:
app/models/list.rb:100:5: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:abort) unless destroyable?
^^^^^^^^^^^^^
app/models/project.rb:2433:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw :abort
^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:26:9: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
catch(:error) do
^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:27:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_(%q(You can't commit to this project)), :forbidden)) unless push_authorized?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:30:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, wrap_error(result)) unless result[:status] == :success
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:65:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('Not found.'), :not_found)) unless self.class.allowed_dashboard_templates.include?(params[:dashboard])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:73:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('There was an error creating the dashboard, branch name is invalid.'), :bad_request)) unless valid_branch_name?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:74:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('There was an error creating the dashboard, branch named: %{branch} already exists.') % { branch: params[:branch] }, :bad_request)) unless new_or_default_branch? # temporary validation for first UI iteration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/clone_dashboard_service.rb:94:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('The file name should have a .yml extension'), :bad_request)) unless target_file_type_valid?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:11:9: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
catch(:error) do
^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:12:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_(%q(You can't commit to this project)), :forbidden)) unless push_authorized?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:15:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, result.merge(http_status: :bad_request)) unless result[:status] == :success
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:49:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('There was an error updating the dashboard, branch name is invalid.'), :bad_request)) unless valid_branch_name?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:50:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('There was an error updating the dashboard, branch named: %{branch} already exists.') % { branch: params[:branch] }, :bad_request)) unless new_or_default_branch?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/metrics/dashboard/update_dashboard_service.rb:74:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:error, error(_('The file name should have a .yml extension'), :bad_request)) unless target_file_type_valid?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/base_service.rb:21:23: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
error_message = catch(:validation_error) do
^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:14:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has at least one commit.')) if project.empty_repo?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:23:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has notes.')) unless note.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:30:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has issues.')) unless issue.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:39:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has merge requests.')) unless merge_request.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:46:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has CI jobs.')) unless build.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:53:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the project has CI pipelines.')) unless pipeline.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/project_service.rb:61:9: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure the wiki is enabled and has pages.'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/services/test_hooks/system_service.rb:21:7: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:validation_error, s_('TestHooks|Ensure one of your projects has merge requests.')) unless merge_request.present?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/gitlab/request_profiler/middleware.rb:54:17: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
ret = catch(:warden) do
^^^^^^^^^^^^^^
lib/gitlab/request_profiler/middleware.rb:70:17: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
ret = catch(:warden) do
^^^^^^^^^^^^^^
lib/gitlab/request_profiler/middleware.rb:102:11: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw(:warden, ret)
^^^^^^^^^^^^^^^^^^^
rubocop/cop/gitlab/keys-first-and-values-first.rb:29:30: C: Cop/BanCatchThrow: Do not use catch or throw unless a gem's API demands it.
throw("Expect '.values.first' or '.keys.first', but get #{node.descendants.first.method_name}.first")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14981 files inspected, 28 offenses detected