From aa05b865dcc9716c104cd25a347b703b7c74aca1 Mon Sep 17 00:00:00 2001 From: David Davis Date: Tue, 8 Oct 2013 12:54:16 -0400 Subject: [PATCH] Rubocop: Fixed failures --- app/controllers/api/api_controller.rb | 6 ++--- .../api/v1/activation_keys_controller.rb | 10 ++++---- app/controllers/api/v1/api_controller.rb | 8 +++---- .../api/v1/changesets_content_controller.rb | 4 ++-- .../api/v1/changesets_controller.rb | 4 ++-- .../v1/content_view_definitions_controller.rb | 2 +- .../api/v1/content_views_controller.rb | 10 ++++---- .../api/v1/custom_info_controller.rb | 2 +- .../api/v1/distributions_controller.rb | 4 ++-- .../api/v1/distributors_controller.rb | 16 ++++++------- .../api/v1/environments_controller.rb | 8 +++---- app/controllers/api/v1/errata_controller.rb | 12 +++++----- .../api/v1/filter_rules_controller.rb | 4 ++-- .../organization_default_info_controller.rb | 6 ++--- app/controllers/api/v1/packages_controller.rb | 6 ++--- .../api/v1/permissions_controller.rb | 4 ++-- app/controllers/api/v1/products_controller.rb | 10 ++++---- .../api/v1/providers_controller.rb | 18 +++++++------- .../api/v1/puppet_modules_controller.rb | 2 +- .../api/v1/repositories_controller.rb | 18 +++++++------- .../api/v1/repository_sets_controller.rb | 10 ++++---- .../api/v1/role_ldap_groups_controller.rb | 2 +- app/controllers/api/v1/roles_controller.rb | 2 +- .../api/v1/subscriptions_controller.rb | 8 +++---- app/controllers/api/v1/sync_controller.rb | 12 +++++----- .../api/v1/sync_plans_controller.rb | 6 ++--- .../api/v1/system_group_errata_controller.rb | 4 ++-- .../v1/system_group_packages_controller.rb | 6 ++--- .../api/v1/system_groups_controller.rb | 6 ++--- .../api/v1/system_packages_controller.rb | 10 ++++---- app/controllers/api/v1/systems_controller.rb | 24 +++++++++---------- app/controllers/api/v1/users_controller.rb | 4 ++-- .../api/v2/changesets_content_controller.rb | 2 +- app/controllers/api/v2/errata_controller.rb | 10 ++++---- .../api/v2/providers_controller.rb | 2 +- .../api/v2/repositories_controller.rb | 2 +- .../api/v2/repository_sets_controller.rb | 2 +- .../api/v2/subscriptions_controller.rb | 6 ++--- .../api/v2/system_errata_controller.rb | 2 +- .../api/v2/system_packages_controller.rb | 10 ++++---- .../api/v2/systems_bulk_actions_controller.rb | 18 +++++++------- app/controllers/application_controller.rb | 6 ++--- app/controllers/changesets_controller.rb | 2 +- app/controllers/packages_controller.rb | 2 +- app/controllers/systems_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- .../experimental/katello_form_builder.rb | 2 +- app/helpers/katello_form_builder.rb | 2 +- app/lib/api/v1/error_handling.rb | 2 +- app/lib/api/v2/error_handling.rb | 2 +- app/lib/authorization_rules.rb | 8 +++---- app/lib/content_search/element.rb | 2 +- app/lib/glue/task.rb | 2 +- app/lib/http_resource.rb | 14 +++++------ app/lib/kt_locale.rb | 2 +- app/lib/lazy_accessor.rb | 6 ++--- app/lib/notifications/controller_helper.rb | 2 +- app/lib/notifications/notifier.rb | 10 ++++---- app/lib/repo_discovery.rb | 2 +- app/lib/resources/candlepin.rb | 10 ++++---- app/lib/resources/cdn.rb | 10 ++++---- app/lib/util/data.rb | 2 +- app/lib/util/thread_session.rb | 4 ++-- app/models/activation_key.rb | 2 +- app/models/async_operation.rb | 2 +- app/models/authorization/content_view.rb | 2 +- .../authorization/content_view_definition.rb | 2 +- .../authorization/content_view_version.rb | 2 +- app/models/authorization/distributor.rb | 2 +- app/models/authorization/enforcement.rb | 12 +++++----- app/models/authorization/environment.rb | 2 +- app/models/authorization/provider.rb | 2 +- app/models/authorization/system.rb | 2 +- app/models/authorization/system_group.rb | 2 +- app/models/candlepin/product_content.rb | 2 +- app/models/changeset.rb | 18 +++++++------- app/models/content_view.rb | 6 ++--- app/models/content_view_definition_base.rb | 8 +++---- app/models/content_view_version.rb | 2 +- .../content_view_version_environment.rb | 2 +- app/models/custom_info.rb | 2 +- app/models/filter_rule.rb | 2 +- app/models/glue.rb | 6 ++--- app/models/glue/candlepin/.rubocop.yml | 3 +++ app/models/glue/candlepin/consumer.rb | 2 +- app/models/glue/candlepin/content.rb | 2 +- app/models/glue/candlepin/environment.rb | 4 ++-- app/models/glue/elastic_search/errata.rb | 2 +- app/models/glue/provider.rb | 6 ++--- app/models/glue/pulp/repo.rb | 12 +++++----- app/models/glue/pulp/repos.rb | 6 ++--- app/models/glue/pulp/user.rb | 2 +- app/models/hypervisor.rb | 2 +- app/models/kt_environment.rb | 2 +- app/models/organization.rb | 6 ++--- app/models/organization_destroyer.rb | 2 +- app/models/permission.rb | 2 +- app/models/ping.rb | 4 ++-- app/models/product.rb | 2 +- app/models/promotion_changeset.rb | 2 +- app/models/provider.rb | 8 +++---- app/models/pulp_task_status.rb | 2 +- app/models/repository.rb | 8 +++---- app/models/resource_type.rb | 2 +- app/models/role.rb | 8 +++---- app/models/system_group.rb | 18 +++++++------- app/models/tag.rb | 4 ++-- app/models/user.rb | 4 ++-- app/models/virtual_tag.rb | 4 ++-- config/application.rb | 2 +- config/initializers/secret_token.rb | 2 +- config/initializers/warden.rb | 4 ++-- ..._environment_default_id_to_content_view.rb | 2 +- db/seeds.rb | 10 ++++---- .../controllers/api/v1/nodes_controller.rb | 2 +- .../app/models/content_node_capability.rb | 2 +- engines/fort/app/models/node_capability.rb | 6 ++--- lib/katello/configuration/loader.rb | 10 ++++---- lib/katello/configuration/node.rb | 6 ++--- lib/katello/configuration/validator.rb | 8 +++---- lib/katello/logging.rb | 4 ++-- lib/monkeys/yard_svg_fix.rb | 2 +- lib/string_to_bool.rb | 2 +- script/update_doc.rb | 2 +- 125 files changed, 333 insertions(+), 330 deletions(-) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 5b0fbbccebe..2f319410d98 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -96,13 +96,13 @@ def split_order(order) def get_resource resource = instance_variable_get(:"@#{resource_name}") - raise 'no resource loaded' if resource.nil? + fail 'no resource loaded' if resource.nil? resource end def get_resource_collection resource = instance_variable_get(:"@#{resource_collection_name}") - raise 'no resource collection loaded' if resource.nil? + fail 'no resource collection loaded' if resource.nil? resource end @@ -116,7 +116,7 @@ def resource_name def respond(options = {}) method_name = ('respond_for_' + params[:action].to_s).to_sym - raise "automatic response method '%s' not defined" % method_name unless respond_to?(method_name, true) + fail "automatic response method '%s' not defined" % method_name unless respond_to?(method_name, true) return send(method_name, options) end end diff --git a/app/controllers/api/v1/activation_keys_controller.rb b/app/controllers/api/v1/activation_keys_controller.rb index 335f931b9b0..509c230c27c 100644 --- a/app/controllers/api/v1/activation_keys_controller.rb +++ b/app/controllers/api/v1/activation_keys_controller.rb @@ -115,7 +115,7 @@ def add_pool api :DELETE, "/activation_keys/:id/pools/:poolid", "Delete an entitlement pool within an activation key" def remove_pool unless @activation_key.pools.include?(@pool) - raise HttpErrors::NotFound, _("Couldn't find pool '%{pool}' in activation_key '%{ak}'") % { :pool => @pool.cp_id, :ak => @activation_key.name } + fail HttpErrors::NotFound, _("Couldn't find pool '%{pool}' in activation_key '%{ak}'") % { :pool => @pool.cp_id, :ak => @activation_key.name } end @activation_key.pools.delete(@pool) respond_for_show @@ -143,13 +143,13 @@ def find_environment return unless params.key?(:environment_id) @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @environment end def find_activation_key @activation_key = ActivationKey.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:id] if @activation_key.nil? + fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % params[:id] if @activation_key.nil? @activation_key end @@ -163,7 +163,7 @@ def find_system_groups if ids ids.each do |group_id| group = SystemGroup.find(group_id) - raise HttpErrors::NotFound, _("Couldn't find system group '%s'") % group_id if group.nil? + fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % group_id if group.nil? @system_groups << group end end @@ -171,6 +171,6 @@ def find_system_groups def verify_presence_of_organization_or_environment return if params.key?(:organization_id) || params.key?(:environment_id) - raise HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified") + fail HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified") end end diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index dd52081811c..397b9538370 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -52,7 +52,7 @@ def query_params def find_organization @organization = find_optional_organization - raise HttpErrors::NotFound, _("One of parameters [%s] required but not specified.") % + fail HttpErrors::NotFound, _("One of parameters [%s] required but not specified.") % organization_id_keys.join(", ") if @organization.nil? @organization end @@ -62,7 +62,7 @@ def find_optional_organization return if org_id.nil? @organization = get_organization(org_id) - raise HttpErrors::NotFound, _("Couldn't find organization '%s'") % org_id if @organization.nil? + fail HttpErrors::NotFound, _("Couldn't find organization '%s'") % org_id if @organization.nil? @organization end @@ -86,14 +86,14 @@ def find_content_view_definition cvd_id = params[:content_view_definition_id] @definition = ContentViewDefinition.find_by_id(cvd_id) if @definition.nil? - raise HttpErrors::NotFound, _("Couildn't find content view with id '%s'") % cvd_id + fail HttpErrors::NotFound, _("Couildn't find content view with id '%s'") % cvd_id end end def find_content_filter_by_name filter_id = params[:filter_id] @filter = Filter.where(:name => filter_id, :content_view_definition_id => @definition).first - raise HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil? + fail HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil? @filter end diff --git a/app/controllers/api/v1/changesets_content_controller.rb b/app/controllers/api/v1/changesets_content_controller.rb index 126f5845986..969dd2f5ede 100644 --- a/app/controllers/api/v1/changesets_content_controller.rb +++ b/app/controllers/api/v1/changesets_content_controller.rb @@ -47,7 +47,7 @@ def find_changeset! def find_content_view! id = params[:action] == "add_content_view" ? params[:content_view_id] : params[:id] @view = ContentView.find_by_id(id) - raise HttpErrors::NotFound, _("Couldn't find content view '%s'") % id if @view.nil? + fail HttpErrors::NotFound, _("Couldn't find content view '%s'") % id if @view.nil? end def render_after_removal(removed_objects, options = {}) @@ -56,7 +56,7 @@ def render_after_removal(removed_objects, options = {}) else rend = { :text => options[:not_found], :status => 404 } end - raise ArgumentError if rend[:text].nil? + fail ArgumentError if rend[:text].nil? render(rend) end diff --git a/app/controllers/api/v1/changesets_controller.rb b/app/controllers/api/v1/changesets_controller.rb index 61161d7bf30..b3a8a5c916c 100644 --- a/app/controllers/api/v1/changesets_controller.rb +++ b/app/controllers/api/v1/changesets_controller.rb @@ -102,14 +102,14 @@ def destroy def find_changeset @changeset = Changeset.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find changeset '%s'") % params[:id] if @changeset.nil? + fail HttpErrors::NotFound, _("Couldn't find changeset '%s'") % params[:id] if @changeset.nil? @environment = @changeset.environment @changeset end def find_environment @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @environment end diff --git a/app/controllers/api/v1/content_view_definitions_controller.rb b/app/controllers/api/v1/content_view_definitions_controller.rb index c95f3034ef7..9e92530b92c 100644 --- a/app/controllers/api/v1/content_view_definitions_controller.rb +++ b/app/controllers/api/v1/content_view_definitions_controller.rb @@ -122,7 +122,7 @@ def publish api :DELETE, "/content_view_definitions/:id", "Delete a cv definition" param :id, :identifier, :desc => "Definition identifier", :required => true def destroy - raise HttpErrors::BadRequest, _("Definition cannot be deleted since one of its views has already been promoted. "\ + fail HttpErrors::BadRequest, _("Definition cannot be deleted since one of its views has already been promoted. "\ "Using a changeset, please delete the views from existing environments before deleting the "\ "definition.") if @definition.has_promoted_views? diff --git a/app/controllers/api/v1/content_views_controller.rb b/app/controllers/api/v1/content_views_controller.rb index 8a47b6a2ea2..d69d5572c01 100644 --- a/app/controllers/api/v1/content_views_controller.rb +++ b/app/controllers/api/v1/content_views_controller.rb @@ -82,7 +82,7 @@ def destroy if @view.destroyed? render :text => _("Deleted content view [ %s ]") % @view.name, :status => 200 else - raise HttpErrors::InternalError, _("Error while deleting content view [ %{name} ]: %{error}") % + fail HttpErrors::InternalError, _("Error while deleting content view [ %{name} ]: %{error}") % { :name => @view.name, :error => @view.errors.full_messages } end end @@ -92,24 +92,24 @@ def destroy def find_content_view @view = ContentView.find(params[:id]) if params[:action] != "show" && @view.default? - raise HttpErrors::BadRequest, _("The default content view cannot be edited, promoted, refreshed, or destroyed.") + fail HttpErrors::BadRequest, _("The default content view cannot be edited, promoted, refreshed, or destroyed.") end end def find_environment @environment = KTEnvironment.find_by_id(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @organization ||= @environment.organization end def find_environment_or_organization if params[:environment_id] @environment = KTEnvironment.find_by_id(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @organization ||= @environment.organization else @organization = get_organization params[:organization_id] - raise HttpErrors::NotFound, _("Couldn't find organization '%s'") % params[:organization_id] if @organization.nil? + fail HttpErrors::NotFound, _("Couldn't find organization '%s'") % params[:organization_id] if @organization.nil? end end diff --git a/app/controllers/api/v1/custom_info_controller.rb b/app/controllers/api/v1/custom_info_controller.rb index a27f1cd8e23..1ba515ba654 100644 --- a/app/controllers/api/v1/custom_info_controller.rb +++ b/app/controllers/api/v1/custom_info_controller.rb @@ -89,7 +89,7 @@ def find_informable def find_custom_info @single_custom_info = CustomInfo.find_by_informable_keyname(@informable, params[:keyname].strip) if @single_custom_info.nil? - raise HttpErrors::NotFound, _("Couldn't find custom info with keyname '%s'") % params[:keyname] + fail HttpErrors::NotFound, _("Couldn't find custom info with keyname '%s'") % params[:keyname] end end diff --git a/app/controllers/api/v1/distributions_controller.rb b/app/controllers/api/v1/distributions_controller.rb index 7d772b1e978..03c22106813 100644 --- a/app/controllers/api/v1/distributions_controller.rb +++ b/app/controllers/api/v1/distributions_controller.rb @@ -41,12 +41,12 @@ def show def find_repository @repo = Repository.find(params[:repository_id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? @repo end def check_distribution - raise HttpErrors::NotFound, _("Distribution '%s' not found within the repository") % params[:id] unless @repo.has_distribution? params[:id] + fail HttpErrors::NotFound, _("Distribution '%s' not found within the repository") % params[:id] unless @repo.has_distribution? params[:id] end end diff --git a/app/controllers/api/v1/distributors_controller.rb b/app/controllers/api/v1/distributors_controller.rb index d31365a3a43..1751ab6c214 100644 --- a/app/controllers/api/v1/distributors_controller.rb +++ b/app/controllers/api/v1/distributors_controller.rb @@ -251,7 +251,7 @@ def task_show def find_only_environment if !@environment && @organization && !params.key?(:environment_id) if @organization.environments.empty? - raise HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for distributor registration.") % + fail HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for distributor registration.") % { :org => @organization.name, :env => "Library" } end @@ -264,7 +264,7 @@ def find_only_environment if current_user.default_environment && current_user.default_environment.organization == @organization @environment = current_user.default_environment else - raise HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for distributor registration.") % @organization.name + fail HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for distributor registration.") % @organization.name end else if @environment = @organization.environments.first @@ -282,7 +282,7 @@ def find_environment return unless params.key?(:environment_id) @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @organization = @environment.organization @environment end @@ -297,7 +297,7 @@ def verify_presence_of_organization_or_environment if @environment @organization = @environment.organization else - raise HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username + fail HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username end end @@ -305,7 +305,7 @@ def find_distributor @distributor = Distributor.first(:conditions => { :uuid => params[:id] }) if @distributor.nil? Resources::Candlepin::Consumer.get params[:id] # check with candlepin if distributor is Gone, raises RestClient::Gone - raise HttpErrors::NotFound, _("Couldn't find distributor '%s'") % params[:id] + fail HttpErrors::NotFound, _("Couldn't find distributor '%s'") % params[:id] end @distributor end @@ -315,21 +315,21 @@ def find_activation_keys ak_names = ak_names.split(",") activation_keys = ak_names.map do |ak_name| activation_key = @organization.activation_keys.find_by_name(ak_name) - raise HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key + fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key activation_key end else activation_keys = [] end if activation_keys.empty? - raise HttpErrors::BadRequest, _("At least one activation key must be provided") + fail HttpErrors::BadRequest, _("At least one activation key must be provided") end activation_keys end def find_task @task = TaskStatus.where(:uuid => params[:id]).first - raise ActiveRecord::RecordNotFound.new unless @task + fail ActiveRecord::RecordNotFound.new unless @task @distributor = @task.task_owner end diff --git a/app/controllers/api/v1/environments_controller.rb b/app/controllers/api/v1/environments_controller.rb index c5f2afac10e..86663f5a2b5 100644 --- a/app/controllers/api/v1/environments_controller.rb +++ b/app/controllers/api/v1/environments_controller.rb @@ -150,7 +150,7 @@ def create environment_params[:label] = labelize_params(environment_params) @environment = KTEnvironment.new(environment_params) @organization.environments << @environment - raise ActiveRecord::RecordInvalid.new(@environment) unless @environment.valid? + fail ActiveRecord::RecordInvalid.new(@environment) unless @environment.valid? @organization.save! respond end @@ -159,7 +159,7 @@ def create api :PUT, "/organizations/:organization_id/environments/:id", "Update an environment in an organization" param_group :environment def update - raise HttpErrors::BadRequest, _("Can't update the '%s' environment") % "Library" if @environment.library? + fail HttpErrors::BadRequest, _("Can't update the '%s' environment") % "Library" if @environment.library? @environment.update_attributes!(params[:environment]) respond end @@ -173,7 +173,7 @@ def destroy @environment.destroy respond :message => _("Deleted environment '%s'") % params[:id] else - raise HttpErrors::BadRequest, + fail HttpErrors::BadRequest, _("Environment %s has a successor. Only the last environment on a path can be deleted.") % @environment.name end end @@ -197,7 +197,7 @@ def releases def find_environment @environment = KTEnvironment.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:id] if @environment.nil? @organization = @environment.organization @environment end diff --git a/app/controllers/api/v1/errata_controller.rb b/app/controllers/api/v1/errata_controller.rb index e175e99cf54..c24af8bd555 100644 --- a/app/controllers/api/v1/errata_controller.rb +++ b/app/controllers/api/v1/errata_controller.rb @@ -46,7 +46,7 @@ def rules def index filter = params.symbolize_keys.slice(:repoid, :repository_id, :product_id, :environment_id, :type, :severity) unless filter[:repoid] || filter[:repository_id] || filter[:environment_id] - raise HttpErrors::BadRequest.new(_("Repo ID or environment must be provided")) + fail HttpErrors::BadRequest.new(_("Repo ID or environment must be provided")) end render :json => Errata.filter(filter) end @@ -61,10 +61,10 @@ def show def find_environment if params.key?(:environment_id) @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? elsif params.key?(:repoid) @repo = Repository.find(params[:repoid]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repoid] if @repo.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repoid] if @repo.nil? @environment = @repo.environment end @environment @@ -73,7 +73,7 @@ def find_environment def find_repository if params.key?(:repository_id) @repo = Repository.find(params[:repository_id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? @environment ||= @repo.environment end @repo @@ -81,9 +81,9 @@ def find_repository def find_erratum @erratum = Errata.find_by_errata_id(params[:id]) - raise HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil? + fail HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil? # and check ownership of it - raise HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id + fail HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id @erratum end end diff --git a/app/controllers/api/v1/filter_rules_controller.rb b/app/controllers/api/v1/filter_rules_controller.rb index 549b38fa730..331b2c16fba 100644 --- a/app/controllers/api/v1/filter_rules_controller.rb +++ b/app/controllers/api/v1/filter_rules_controller.rb @@ -78,14 +78,14 @@ def find_definition def find_filter id = params[:filter_id] @filter = Filter.where(:id => id, :content_view_definition_id => @definition).first - raise HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil? + fail HttpErrors::NotFound, _("Couldn't find filter '%s'") % params[:id] if @filter.nil? @filter end def find_filter_rule id = params[:id] @filter_rule = FilterRule.where(:filter_id => @filter.id, :id => id).first - raise HttpErrors::NotFound, _("Couldn't find filter rule '%s'") % params[:id] if @filter_rule.nil? + fail HttpErrors::NotFound, _("Couldn't find filter rule '%s'") % params[:id] if @filter_rule.nil? @filter_rule end diff --git a/app/controllers/api/v1/organization_default_info_controller.rb b/app/controllers/api/v1/organization_default_info_controller.rb index 328c537b1e3..c8a56a1a65c 100644 --- a/app/controllers/api/v1/organization_default_info_controller.rb +++ b/app/controllers/api/v1/organization_default_info_controller.rb @@ -42,7 +42,7 @@ def rules def create inf_type = params[:informable_type] if @organization.default_info[inf_type].include?(params[:keyname]) - raise HttpErrors::BadRequest, + fail HttpErrors::BadRequest, _("Organization [ %{org} ] already contains default info [ %{info} ] for [ %{object} ]") % { :org => @organization.name, :info => params[:keyname], :object => inf_type.capitalize.pluralize } end @@ -105,7 +105,7 @@ def check_informable_type def check_apply_default_info if @organization.applying_default_info? - raise HttpErrors::BadRequest, + fail HttpErrors::BadRequest, _("Organization [ %{org} ] is currently applying default custom info. Please try again later.") % { :org => @organization.name } end @@ -113,7 +113,7 @@ def check_apply_default_info def find_default_info unless @organization.default_info[params[:informable_type]].include?(params[:keyname]) - raise HttpErrors::NotFound, _("Couldn't find default_info with keyname [ %{keyname} ]") % + fail HttpErrors::NotFound, _("Couldn't find default_info with keyname [ %{keyname} ]") % { :keyname => params[:keyname] } end end diff --git a/app/controllers/api/v1/packages_controller.rb b/app/controllers/api/v1/packages_controller.rb index c706ccffc34..7694475fe12 100644 --- a/app/controllers/api/v1/packages_controller.rb +++ b/app/controllers/api/v1/packages_controller.rb @@ -51,15 +51,15 @@ def show def find_repository @repo = Repository.find(params[:repository_id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? @repo end def find_package @package = Package.find(params[:id]) - raise HttpErrors::NotFound, _("Package with id '%s' not found") % params[:id] if @package.nil? + fail HttpErrors::NotFound, _("Package with id '%s' not found") % params[:id] if @package.nil? # and check ownership of it - raise HttpErrors::NotFound, _("Package '%s' not found within the repository") % params[:id] unless @package.repoids.include? @repo.pulp_id + fail HttpErrors::NotFound, _("Package '%s' not found within the repository") % params[:id] unless @package.repoids.include? @repo.pulp_id @package end end diff --git a/app/controllers/api/v1/permissions_controller.rb b/app/controllers/api/v1/permissions_controller.rb index 539fcdfad29..8454ef90bd8 100644 --- a/app/controllers/api/v1/permissions_controller.rb +++ b/app/controllers/api/v1/permissions_controller.rb @@ -98,13 +98,13 @@ def destroy def find_role @role = Role.find(params[:role_id]) - raise HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:role_id] if @role.nil? + fail HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:role_id] if @role.nil? @role end def find_permission @permission = Permission.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find permissions '%s'") % params[:id] if @permission.nil? + fail HttpErrors::NotFound, _("Couldn't find permissions '%s'") % params[:id] if @permission.nil? @permission end end diff --git a/app/controllers/api/v1/products_controller.rb b/app/controllers/api/v1/products_controller.rb index c0d2ba1aa19..8d0b2129047 100644 --- a/app/controllers/api/v1/products_controller.rb +++ b/app/controllers/api/v1/products_controller.rb @@ -64,7 +64,7 @@ def show param :recursive, :bool, :desc => "set to true to recursive update gpg key" end def update - raise HttpErrors::BadRequest, _("Red Hat products cannot be updated.") if @product.redhat? + fail HttpErrors::BadRequest, _("Red Hat products cannot be updated.") if @product.redhat? @product.gpg_key_name = params[:product][:gpg_key_name] unless params[:product][:gpg_key_name].nil? # not .blank? @product.update_attributes!(params[:product].slice(:description)) if params[:product][:recursive] @@ -138,9 +138,9 @@ def remove_sync_plan private def find_product - raise _("Neither organization nor environment has been provided.") if @organization.nil? + fail _("Neither organization nor environment has been provided.") if @organization.nil? @product = Product.find_by_cp_id(params[:id], @organization) - raise HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:id] if @product.nil? + fail HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:id] if @product.nil? end def find_environment @@ -149,7 +149,7 @@ def find_environment @environment = @product.organization.library unless @product.nil? else @environment = KTEnvironment.find_by_id(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? end @organization ||= @environment.organization if @environment end @@ -163,7 +163,7 @@ def find_content_view def verify_presence_of_organization_or_environment return if @organization || @environment - raise HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified") + fail HttpErrors::BadRequest, _("Either organization ID or environment ID needs to be specified") end end diff --git a/app/controllers/api/v1/providers_controller.rb b/app/controllers/api/v1/providers_controller.rb index f994d9c98c6..d31ba858c90 100644 --- a/app/controllers/api/v1/providers_controller.rb +++ b/app/controllers/api/v1/providers_controller.rb @@ -106,14 +106,14 @@ def destroy # # TODO: these should really be done as validations, but the orchestration engine currently converts them into OrchestrationExceptions # rubocop:disable LineLength - raise HttpErrors::BadRequest, _("Provider cannot be deleted since one of its products or repositories has already been promoted. Using a changeset, please delete the repository from existing environments before deleting it.") if @provider.repositories.any? { |r| r.promoted? } + fail HttpErrors::BadRequest, _("Provider cannot be deleted since one of its products or repositories has already been promoted. Using a changeset, please delete the repository from existing environments before deleting it.") if @provider.repositories.any? { |r| r.promoted? } @provider.destroy if @provider.destroyed? respond :message => _("Deleted provider [ %s ]") % @provider.name else # TOOO: should probably be more specific? - raise HttpErrors::InternalError, _("Error while deleting provider [ %{name} ]: %{error}") % { :name => @provider.name, :error => @provider.errors.full_messages } + fail HttpErrors::InternalError, _("Error while deleting provider [ %{name} ]: %{error}") % { :name => @provider.name, :error => @provider.errors.full_messages } end end @@ -133,7 +133,7 @@ def products param :force, :bool, :desc => "Force import" def import_manifest if @provider.yum_repo? - raise HttpErrors::BadRequest, _("Manifests cannot be imported for a custom provider.") + fail HttpErrors::BadRequest, _("Manifests cannot be imported for a custom provider.") end begin @@ -153,7 +153,7 @@ def import_manifest param :id, :number, :desc => "Provider numeric identifier", :required => true def refresh_manifest if @provider.yum_repo? - raise HttpErrors::BadRequest, _("Manifests cannot be imported for a custom provider.") + fail HttpErrors::BadRequest, _("Manifests cannot be imported for a custom provider.") end details = @provider.organization.owner_details @@ -166,7 +166,7 @@ def refresh_manifest param :id, :number, :desc => "Provider numeric identifier", :required => true def delete_manifest if @provider.yum_repo? - raise HttpErrors::BadRequest, _("Manifests cannot be deleted for a custom provider.") + fail HttpErrors::BadRequest, _("Manifests cannot be deleted for a custom provider.") end @provider.delete_manifest @@ -176,7 +176,7 @@ def delete_manifest api :POST, "/providers/:id/refresh_products", "Refresh products for Red Hat provider" param :id, :number, :desc => "Provider numeric identifier", :required => true def refresh_products - raise HttpErrors::BadRequest, _("Products cannot be refreshed for custom provider.") unless @provider.redhat_provider? + fail HttpErrors::BadRequest, _("Products cannot be refreshed for custom provider.") unless @provider.redhat_provider? @provider.refresh_products respond_for_status :message => _("Products refreshed from CDN") @@ -206,7 +206,7 @@ def import_products end api_version "v1" def product_create - raise HttpErrors::BadRequest, _("Products cannot be created for the Red Hat provider.") if @provider.redhat_provider? + fail HttpErrors::BadRequest, _("Products cannot be created for the Red Hat provider.") if @provider.redhat_provider? product_params = params[:product] @@ -216,7 +216,7 @@ def product_create # in the ui could be the result of an initial query to retrieve a default label) if !product_params[:label].blank? && (Product.all_in_org(@provider.organization).where('products.label = ?', product_params[:label]).count > 0) - raise HttpErrors::BadRequest, _("Validation failed: Label has already been taken") + fail HttpErrors::BadRequest, _("Validation failed: Label has already been taken") end gpg = GpgKey.readable(@provider.organization).find_by_name!(product_params[:gpg_key_name]) unless product_params[:gpg_key_name].blank? @@ -229,7 +229,7 @@ def product_create def find_provider @provider = Provider.find(params[:id]) @organization ||= @provider.organization - raise HttpErrors::NotFound, _("Couldn't find provider '%s'") % params[:id] if @provider.nil? + fail HttpErrors::NotFound, _("Couldn't find provider '%s'") % params[:id] if @provider.nil? end end diff --git a/app/controllers/api/v1/puppet_modules_controller.rb b/app/controllers/api/v1/puppet_modules_controller.rb index 431a02243ae..2735ee77897 100644 --- a/app/controllers/api/v1/puppet_modules_controller.rb +++ b/app/controllers/api/v1/puppet_modules_controller.rb @@ -62,7 +62,7 @@ def find_puppet_module @puppet_module = PuppetModule.find(params[:id]) unless @puppet_module.repoids.include?(@repo.pulp_id) - raise HttpErrors::NotFound, _("Puppet module '%{id}' not found within repository '%{repo}'") % + fail HttpErrors::NotFound, _("Puppet module '%{id}' not found within repository '%{repo}'") % {:id => params[:id], :repo => @repo.name} end end diff --git a/app/controllers/api/v1/repositories_controller.rb b/app/controllers/api/v1/repositories_controller.rb index 0157f93f89d..457a543e400 100644 --- a/app/controllers/api/v1/repositories_controller.rb +++ b/app/controllers/api/v1/repositories_controller.rb @@ -62,7 +62,7 @@ def param_rules param :content_type, String, :desc => "type of repo (either 'yum' or 'puppet', defaults to 'yum')" see "v1#gpg_keys#index" def create - raise HttpErrors::BadRequest, _("Repository can be only created for custom provider.") unless @product.custom? + fail HttpErrors::BadRequest, _("Repository can be only created for custom provider.") unless @product.custom? if params[:gpg_key_name].present? gpg = GpgKey.readable(@product.organization).find_by_name!(params[:gpg_key_name]) @@ -89,7 +89,7 @@ def show param :url, String, :desc => "repository source url" end def update - raise HttpErrors::BadRequest, _("A Red Hat repository cannot be updated.") if @repository.redhat? + fail HttpErrors::BadRequest, _("A Red Hat repository cannot be updated.") if @repository.redhat? attrs = params[:repository].slice(:gpg_key_name, :enabled) attrs[:feed] = params[:repository][:url] if params[:repository] && params[:repository][:url] @repository.update_attributes!(attrs) @@ -102,12 +102,12 @@ def destroy # # TODO: these should really be done as validations, but the orchestration engine currently converts them into OrchestrationExceptions # - raise HttpErrors::BadRequest, _("Repositories can be deleted only in the '%s' environment.") % "Library" if !@repository.environment.library? + fail HttpErrors::BadRequest, _("Repositories can be deleted only in the '%s' environment.") % "Library" if !@repository.environment.library? if @repository.destroy respond :message => _("Deleted repository '%s'") % params[:id] else - raise HttpErrors::BadRequest, @repository.errors.full_messages.join(" ") + fail HttpErrors::BadRequest, @repository.errors.full_messages.join(" ") end end @@ -116,7 +116,7 @@ def destroy param :enable, :bool, :required => true, :desc => "flag that enables/disables the repository" api_version "v1" def enable - raise HttpErrors::NotFound, _("Disable/enable is not supported for custom repositories.") if !@repository.redhat? + fail HttpErrors::NotFound, _("Disable/enable is not supported for custom repositories.") if !@repository.redhat? @repository.enabled = query_params[:enable] @repository.save! @@ -144,7 +144,7 @@ def sync_complete if forwarded && !['127.0.0.1', '::1'].include?(forwarded) Rails.logger.error("Attempt to access sync_complete from forwarded address #{forwarded}") - raise Errors::SecurityViolation + fail Errors::SecurityViolation end repo_id = params['payload']['repo_id'] @@ -156,7 +156,7 @@ def sync_complete end repo = Repository.where(:pulp_id => repo_id).first - raise _("Couldn't find repository '%s'") % repo.name if repo.nil? + fail _("Couldn't find repository '%s'") % repo.name if repo.nil? Rails.logger.info("Sync_complete called for #{repo.name}, running after_sync.") repo.async(:organization => repo.environment.organization).after_sync(task_id) respond_for_status @@ -199,14 +199,14 @@ def gpg_key_content def find_repository @repository = Repository.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:id] if @repository.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:id] if @repository.nil? @repository end def find_product #since this is only used for create, it isn't supported for rhel products, so cp_id is unique @product = Product.where(:cp_id => params[:product_id]).first - raise HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? + fail HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? @organization ||= @product.organization end end diff --git a/app/controllers/api/v1/repository_sets_controller.rb b/app/controllers/api/v1/repository_sets_controller.rb index d8c1702fbea..9565f94c372 100644 --- a/app/controllers/api/v1/repository_sets_controller.rb +++ b/app/controllers/api/v1/repository_sets_controller.rb @@ -34,7 +34,7 @@ def rules param :product_id, :number, :required => true, :desc => "id of a product the repository will be contained in" param :id, :number, :required => true, :desc => "id or name of the repository set to enable" def enable - raise _('Repository sets are enabled by default for custom products..') if @product.custom? + fail _('Repository sets are enabled by default for custom products..') if @product.custom? respond_for_async :resource => @product.async(:organization => @organization).refresh_content(@product_content.content.id) end @@ -43,14 +43,14 @@ def enable param :product_id, :number, :required => true, :desc => "id of a product the repository will be contained in" param :id, :number, :required => true, :desc => "id of the repository set to disable" def disable - raise _('Repository sets are not applicable for custom products..') if @product.custom? + fail _('Repository sets are not applicable for custom products..') if @product.custom? respond_for_async :resource => @product.async(:organization => @organization).disable_content(@product_content.content.id) end api :GET, "/organizations/:organization_id/product/:product_id/repository_sets/", "List repository sets for a product." param :product_id, :number, :required => true, :desc => "id of a product to list repository sets for" def index - raise _('Repository sets are not available for custom products.') if @product.custom? + fail _('Repository sets are not available for custom products.') if @product.custom? content = @product.productContent.collect do |pc| content = pc.content.as_json.symbolize_keys content[:katello_enabled] = pc.katello_enabled? @@ -64,12 +64,12 @@ def index def find_product_content @product_content = @product.product_content_by_id(params[:id]) @product_content ||= @product.product_content_by_name(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find repository set with id '%s'.") % params[:id] if @product_content.nil? + fail HttpErrors::NotFound, _("Couldn't find repository set with id '%s'.") % params[:id] if @product_content.nil? end def find_product @product = Product.find_by_cp_id(params[:product_id], @organization) - raise HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? + fail HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? @organization = @product.organization end end diff --git a/app/controllers/api/v1/role_ldap_groups_controller.rb b/app/controllers/api/v1/role_ldap_groups_controller.rb index 27d3483e449..863647c338d 100644 --- a/app/controllers/api/v1/role_ldap_groups_controller.rb +++ b/app/controllers/api/v1/role_ldap_groups_controller.rb @@ -50,7 +50,7 @@ def index def find_role @role = Role.find(params[:role_id]) - raise HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:role_id] if @role.nil? + fail HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:role_id] if @role.nil? @role end diff --git a/app/controllers/api/v1/roles_controller.rb b/app/controllers/api/v1/roles_controller.rb index 1cffad21775..e322e2ee767 100644 --- a/app/controllers/api/v1/roles_controller.rb +++ b/app/controllers/api/v1/roles_controller.rb @@ -103,7 +103,7 @@ def available_verbs def find_role @role = Role.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:id] if @role.nil? + fail HttpErrors::NotFound, _("Couldn't find user role '%s'") % params[:id] if @role.nil? @role end diff --git a/app/controllers/api/v1/subscriptions_controller.rb b/app/controllers/api/v1/subscriptions_controller.rb index 657ee9b564b..d7df4f39df7 100644 --- a/app/controllers/api/v1/subscriptions_controller.rb +++ b/app/controllers/api/v1/subscriptions_controller.rb @@ -96,7 +96,7 @@ def organization_index param :quantity, :number, :desc => "Number of subscription to use", :required => true def create expected_params = params.with_indifferent_access.slice(:pool, :quantity) - raise HttpErrors::BadRequest, _("Please provide pool and quantity") if expected_params.count != 2 + fail HttpErrors::BadRequest, _("Please provide pool and quantity") if expected_params.count != 2 @system.subscribe(expected_params[:pool], expected_params[:quantity]) respond :resource => @system end @@ -106,7 +106,7 @@ def create param_group :system def destroy expected_params = params.with_indifferent_access.slice(:id) - raise HttpErrors::BadRequest, _("Please provide subscription ID") if expected_params.count != 1 + fail HttpErrors::BadRequest, _("Please provide subscription ID") if expected_params.count != 1 @system.unsubscribe(expected_params[:id]) respond_for_show :resource => @system end @@ -123,7 +123,7 @@ def destroy_all param_group :system def destroy_by_serial expected_params = params.with_indifferent_access.slice(:serial_id) - raise HttpErrors::BadRequest, _("Please provide serial ID") if expected_params.count != 1 + fail HttpErrors::BadRequest, _("Please provide serial ID") if expected_params.count != 1 @system.unsubscribe_by_serial(expected_params[:serial_id]) respond_for_show :resource => @system end @@ -132,7 +132,7 @@ def destroy_by_serial def find_system @system = System.first(:conditions => { :uuid => params[:system_id] }) - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? @system end diff --git a/app/controllers/api/v1/sync_controller.rb b/app/controllers/api/v1/sync_controller.rb index 96b02b58cd4..96d05b3abda 100644 --- a/app/controllers/api/v1/sync_controller.rb +++ b/app/controllers/api/v1/sync_controller.rb @@ -81,33 +81,33 @@ def find_object elsif params.key?(:repository_id) @obj = find_repository else - raise HttpErrors::NotFound, N_("Couldn't find subject of synchronization") if @obj.nil? + fail HttpErrors::NotFound, N_("Couldn't find subject of synchronization") if @obj.nil? end @obj end def find_provider @provider = Provider.find(params[:provider_id]) - raise HttpErrors::BadRequest, N_("Couldn't find provider '%s'") % params[:provider_id] if @provider.nil? + fail HttpErrors::BadRequest, N_("Couldn't find provider '%s'") % params[:provider_id] if @provider.nil? @provider end def find_product - raise _("Organization required") if @organization.nil? + fail _("Organization required") if @organization.nil? @product = Product.find_by_cp_id(params[:product_id], @organization) - raise HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? + fail HttpErrors::NotFound, _("Couldn't find product with id '%s'") % params[:product_id] if @product.nil? @product end def find_repository @repository = Repository.find(params[:repository_id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repository.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repository.nil? @repository end def ensure_library unless @repository.nil? - raise HttpErrors::NotFound, _("You can synchronize repositories only in library environment'") if !@repository.environment.library? + fail HttpErrors::NotFound, _("You can synchronize repositories only in library environment'") if !@repository.environment.library? end end diff --git a/app/controllers/api/v1/sync_plans_controller.rb b/app/controllers/api/v1/sync_plans_controller.rb index 3d067691305..0230a2d9b16 100644 --- a/app/controllers/api/v1/sync_plans_controller.rb +++ b/app/controllers/api/v1/sync_plans_controller.rb @@ -78,7 +78,7 @@ def create sync_date = params[:sync_plan][:sync_date].to_time if !sync_date.kind_of?(Time) - raise _("Date format is incorrect.") + fail _("Date format is incorrect.") end params[:sync_plan][:organization] = @organization @@ -92,7 +92,7 @@ def update sync_date = params[:sync_plan][:sync_date].to_time if !sync_date.nil? && !sync_date.kind_of?(Time) - raise _("Date format is incorrect.") + fail _("Date format is incorrect.") end @plan.update_attributes!(params[:sync_plan]) @@ -110,7 +110,7 @@ def destroy def find_plan @plan = SyncPlan.find(params[:id]) - raise HttpErrors::NotFound, _("Couldn't find sync plan '%{plan}' in organization '%{org}'") % { :plan => params[:id], :org => params[:organization_id] } if @plan.nil? + fail HttpErrors::NotFound, _("Couldn't find sync plan '%{plan}' in organization '%{org}'") % { :plan => params[:id], :org => params[:organization_id] } if @plan.nil? @organization ||= @plan.organization @plan end diff --git a/app/controllers/api/v1/system_group_errata_controller.rb b/app/controllers/api/v1/system_group_errata_controller.rb index 6af6d96349a..a75af6a11af 100644 --- a/app/controllers/api/v1/system_group_errata_controller.rb +++ b/app/controllers/api/v1/system_group_errata_controller.rb @@ -59,13 +59,13 @@ def create def find_group @group = SystemGroup.find(params[:system_group_id]) - raise HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:system_group_id] if @group.nil? + fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:system_group_id] if @group.nil? @group end def require_errata if params.slice(:errata_ids).values.size != 1 - raise HttpErrors::BadRequest.new(_("One or more errata must be provided")) + fail HttpErrors::BadRequest.new(_("One or more errata must be provided")) end end diff --git a/app/controllers/api/v1/system_group_packages_controller.rb b/app/controllers/api/v1/system_group_packages_controller.rb index 429ec5e5ada..09bc0093121 100644 --- a/app/controllers/api/v1/system_group_packages_controller.rb +++ b/app/controllers/api/v1/system_group_packages_controller.rb @@ -90,7 +90,7 @@ def destroy def find_group @group = SystemGroup.find(params[:system_group_id]) - raise HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:system_group_id] if @group.nil? + fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:system_group_id] if @group.nil? @group end @@ -101,7 +101,7 @@ def valid_package_name?(package_name) def validate_package_list_format(packages) packages.each do |package_name| if !valid_package_name?(package_name) - raise HttpErrors::BadRequest.new(_("%s is not a valid package name") % package_name) + fail HttpErrors::BadRequest.new(_("%s is not a valid package name") % package_name) end end @@ -110,7 +110,7 @@ def validate_package_list_format(packages) def require_packages_or_groups if params.slice(:packages, :groups).values.size != 1 - raise HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) + fail HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) end end diff --git a/app/controllers/api/v1/system_groups_controller.rb b/app/controllers/api/v1/system_groups_controller.rb index 3b7078a3c4d..94730d3fe11 100644 --- a/app/controllers/api/v1/system_groups_controller.rb +++ b/app/controllers/api/v1/system_groups_controller.rb @@ -192,7 +192,7 @@ def create end def copy if @organization.id != @system_group.organization.id - raise HttpErrors::BadRequest, + fail HttpErrors::BadRequest, _("Can't copy System Groups to a different org: '%{org1}' != '%{org2}'") % { :org1 => @organization.id, :org2 => @system_group.organization.id } end grp_param = params[:system_group] @@ -267,12 +267,12 @@ def update_systems def find_group @system_group = SystemGroup.where(:id => params[:id]).first - raise HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:id] if @system_group.nil? + fail HttpErrors::NotFound, _("Couldn't find system group '%s'") % params[:id] if @system_group.nil? end def system_uuids_to_ids(ids) system_ids = System.where(:uuid => ids).collect { |s| s.id } - raise Errors::NotFound.new(_("Systems [%s] not found.") % ids.join(',')) if system_ids.blank? + fail Errors::NotFound.new(_("Systems [%s] not found.") % ids.join(',')) if system_ids.blank? system_ids end diff --git a/app/controllers/api/v1/system_packages_controller.rb b/app/controllers/api/v1/system_packages_controller.rb index 83b4c6b0f48..74bc6f15b53 100644 --- a/app/controllers/api/v1/system_packages_controller.rb +++ b/app/controllers/api/v1/system_packages_controller.rb @@ -89,7 +89,7 @@ def destroy def find_system @system = System.first(:conditions => { :uuid => params[:system_id] }) - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? @system end @@ -100,7 +100,7 @@ def valid_package_name?(package_name) def validate_package_list_format(packages) packages.each do |package| if !valid_package_name?(package) && !package.is_a?(Hash) - raise HttpErrors::BadRequest.new(_("%s is not a valid package name") % package) + fail HttpErrors::BadRequest.new(_("%s is not a valid package name") % package) end end @@ -109,17 +109,17 @@ def validate_package_list_format(packages) def require_packages_or_groups if params.slice(:packages, :groups).values.size != 1 - raise HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) + fail HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) end end def require_packages_only if params[:groups] - raise HttpErrors::BadRequest.new(_("This action doesn't support pacakge groups")) + fail HttpErrors::BadRequest.new(_("This action doesn't support pacakge groups")) end unless params[:packages] - raise HttpErrors::BadRequest.new(_("Packages must be provided")) + fail HttpErrors::BadRequest.new(_("Packages must be provided")) end end diff --git a/app/controllers/api/v1/systems_controller.rb b/app/controllers/api/v1/systems_controller.rb index 9e0be168b92..b0e1ec99705 100644 --- a/app/controllers/api/v1/systems_controller.rb +++ b/app/controllers/api/v1/systems_controller.rb @@ -294,7 +294,7 @@ def errata param :id, String, :desc => "UUID of the system", :required => true def upload_package_profile if Katello.config.katello? - raise HttpErrors::BadRequest, _("No package profile received for %s") % @system.name unless params.key?(:_json) + fail HttpErrors::BadRequest, _("No package profile received for %s") % @system.name unless params.key?(:_json) @system.upload_package_profile(params[:_json]) end respond_for_update @@ -477,7 +477,7 @@ def refresh_subscriptions def find_only_environment if !@environment && @organization && !params.key?(:environment_id) if @organization.environments.empty? - raise HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for system registration.") % + fail HttpErrors::BadRequest, _("Organization %{org} has the '%{env}' environment only. Please create an environment for system registration.") % { :org => @organization.name, :env => "Library" } end @@ -490,7 +490,7 @@ def find_only_environment if current_user.default_environment && current_user.default_environment.organization == @organization @environment = current_user.default_environment else - raise HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for system registration.") % @organization.name + fail HttpErrors::BadRequest, _("Organization %s has more than one environment. Please specify target environment for system registration.") % @organization.name end else if @environment = @organization.environments.first @@ -514,10 +514,10 @@ def get_content_view_environment(key, value) cve = nil if value cve = ContentViewEnvironment.where(key => value).first - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % value unless cve + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % value unless cve if @organization.nil? || !@organization.readable? unless cve.content_view.readable? || User.consumer? - raise Errors::SecurityViolation, _("Could not access content view in environment '%s'") % value + fail Errors::SecurityViolation, _("Could not access content view in environment '%s'") % value end end end @@ -532,7 +532,7 @@ def find_environment return unless params.key?(:environment_id) @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @organization = @environment.organization @environment end @@ -553,7 +553,7 @@ def find_environment_and_content_view # assumption here is :content_view_id is passed as a separate attrib @environment = KTEnvironment.find(params[:environment_id]) @organization = @environment.organization - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? end return @environment, @content_view else @@ -571,7 +571,7 @@ def verify_presence_of_organization_or_environment if @environment @organization = @environment.organization else - raise HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username + fail HttpErrors::NotFound, _("You have not set a default organization and environment on the user %s.") % current_user.username end end @@ -579,7 +579,7 @@ def find_system @system = System.first(:conditions => { :uuid => params[:id] }) if @system.nil? Resources::Candlepin::Consumer.get params[:id] # check with candlepin if system is Gone, raises RestClient::Gone - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:id] + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:id] end @system end @@ -589,14 +589,14 @@ def find_activation_keys ak_names = ak_names.split(",") activation_keys = ak_names.map do |ak_name| activation_key = @organization.activation_keys.find_by_name(ak_name) - raise HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key + fail HttpErrors::NotFound, _("Couldn't find activation key '%s'") % ak_name unless activation_key activation_key end else activation_keys = [] end if activation_keys.empty? - raise HttpErrors::BadRequest, _("At least one activation key must be provided") + fail HttpErrors::BadRequest, _("At least one activation key must be provided") end activation_keys end @@ -618,7 +618,7 @@ def setup_content_view(cv_id) organization ||= @environment.organization if @environment if cv_id && organization @content_view = ContentView.readable(organization).find_by_id(cv_id) - raise HttpErrors::NotFound, _("Couldn't find content view '%s'") % cv_id if @content_view.nil? + fail HttpErrors::NotFound, _("Couldn't find content view '%s'") % cv_id if @content_view.nil? else @content_view = nil end diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2590df59bd0..d3c7779b514 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -184,13 +184,13 @@ def list_owners def find_user @user = User.find(params[:user_id] || params[:id]) - raise HttpErrors::NotFound, _("Couldn't find user '%s'") % params[:id] if @user.nil? + fail HttpErrors::NotFound, _("Couldn't find user '%s'") % params[:id] if @user.nil? @user end def find_user_by_username @user = User.find_by_username(params[:username]) - raise HttpErrors::NotFound, _("Couldn't find user '%s'") % params[:username] if @user.nil? + fail HttpErrors::NotFound, _("Couldn't find user '%s'") % params[:username] if @user.nil? @user end diff --git a/app/controllers/api/v2/changesets_content_controller.rb b/app/controllers/api/v2/changesets_content_controller.rb index 9dad7486530..17e21703399 100644 --- a/app/controllers/api/v2/changesets_content_controller.rb +++ b/app/controllers/api/v2/changesets_content_controller.rb @@ -51,7 +51,7 @@ def find_changeset def find_content_view content_view_id = params.try(:[], :content_view).try(:[], :id) || params.try(:[], :id) @view = ContentView.find_by_id(content_view_id) - raise HttpErrors::NotFound, _("Couldn't find content view '%s'") % content_view_id if @view.nil? + fail HttpErrors::NotFound, _("Couldn't find content view '%s'") % content_view_id if @view.nil? end end diff --git a/app/controllers/api/v2/errata_controller.rb b/app/controllers/api/v2/errata_controller.rb index 6b1a2117e68..a795d370801 100644 --- a/app/controllers/api/v2/errata_controller.rb +++ b/app/controllers/api/v2/errata_controller.rb @@ -56,7 +56,7 @@ def show def find_environment if params.key?(:environment_id) @environment = KTEnvironment.find(params[:environment_id]) - raise HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? + fail HttpErrors::NotFound, _("Couldn't find environment '%s'") % params[:environment_id] if @environment.nil? @environment end end @@ -64,7 +64,7 @@ def find_environment def find_repository if params.key?(:repository_id) @repo = Repository.find(params[:repository_id]) - raise HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? + fail HttpErrors::NotFound, _("Couldn't find repository '%s'") % params[:repository_id] if @repo.nil? @environment ||= @repo.environment @repo end @@ -72,12 +72,12 @@ def find_repository def find_erratum @erratum = Errata.find(params[:id]) - raise HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil? - raise HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id + fail HttpErrors::NotFound, _("Erratum with id '%s' not found") % params[:id] if @erratum.nil? + fail HttpErrors::NotFound, _("Erratum '%s' not found within the repository") % params[:id] unless @erratum.repoids.include? @repo.pulp_id @erratum end def require_repo_or_environment - raise HttpErrors::BadRequest, _("Either repository or environment is required.") % params[:id] if @repo.nil? && @environment.nil? + fail HttpErrors::BadRequest, _("Either repository or environment is required.") % params[:id] if @repo.nil? && @environment.nil? end end diff --git a/app/controllers/api/v2/providers_controller.rb b/app/controllers/api/v2/providers_controller.rb index ec61df7aa6a..f7f81339dc6 100644 --- a/app/controllers/api/v2/providers_controller.rb +++ b/app/controllers/api/v2/providers_controller.rb @@ -77,7 +77,7 @@ def create def find_provider @provider = Provider.find(params[:id]) @organization ||= @provider.organization - raise HttpErrors::NotFound, _("Couldn't find provider '%s'") % params[:id] if @provider.nil? + fail HttpErrors::NotFound, _("Couldn't find provider '%s'") % params[:id] if @provider.nil? end end diff --git a/app/controllers/api/v2/repositories_controller.rb b/app/controllers/api/v2/repositories_controller.rb index 55c753e7b15..b38de6e3b09 100644 --- a/app/controllers/api/v2/repositories_controller.rb +++ b/app/controllers/api/v2/repositories_controller.rb @@ -110,7 +110,7 @@ def show param :id, :identifier, :required => true, :desc => "repository id" param :gpg_key_id, :number, :desc => "id of a gpg key that will be assigned to this repository" def update - raise HttpErrors::BadRequest, _("A Red Hat repository cannot be updated.") if @repository.redhat? + fail HttpErrors::BadRequest, _("A Red Hat repository cannot be updated.") if @repository.redhat? @repository.update_attributes!(params.slice(:gpg_key_id, :feed)) respond_for_show(:resource => @repository) end diff --git a/app/controllers/api/v2/repository_sets_controller.rb b/app/controllers/api/v2/repository_sets_controller.rb index 7ec30ba2d09..58a1fd9de7a 100644 --- a/app/controllers/api/v2/repository_sets_controller.rb +++ b/app/controllers/api/v2/repository_sets_controller.rb @@ -21,7 +21,7 @@ class Api::V2::RepositorySetsController < Api::V1::RepositorySetsController api :GET, "/product/:product_id/repository_sets/", "List repository sets for a product." param :product_id, :number, :required => true, :desc => "id of a product to list repository sets for" def index - raise _('Repository sets are not available for custom products.') if @product.custom? + fail _('Repository sets are not available for custom products.') if @product.custom? respond :collection => @product.productContent end diff --git a/app/controllers/api/v2/subscriptions_controller.rb b/app/controllers/api/v2/subscriptions_controller.rb index 0321bc96f3d..9c7799d1409 100644 --- a/app/controllers/api/v2/subscriptions_controller.rb +++ b/app/controllers/api/v2/subscriptions_controller.rb @@ -80,7 +80,7 @@ def available end def create expected_params = params.slice(:pool, :quantity) - raise HttpErrors::BadRequest, _("Please provide pool and quantity") if expected_params.count != 2 + fail HttpErrors::BadRequest, _("Please provide pool and quantity") if expected_params.count != 2 @system.subscribe(expected_params[:pool], expected_params[:quantity]) respond :resource => @system end @@ -90,7 +90,7 @@ def create param :system_id, String, :desc => "UUID of the system", :required => true def destroy expected_params = params.slice(:id) - raise HttpErrors::BadRequest, _("Please provide subscription ID") if expected_params.count != 1 + fail HttpErrors::BadRequest, _("Please provide subscription ID") if expected_params.count != 1 @system.unsubscribe(expected_params[:id]) respond_for_show :resource => @system end @@ -106,7 +106,7 @@ def destroy_all def find_system @system = System.first(:conditions => { :uuid => params[:system_id] }) - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? @system end end diff --git a/app/controllers/api/v2/system_errata_controller.rb b/app/controllers/api/v2/system_errata_controller.rb index 3b0a3227f4d..94b54accc02 100644 --- a/app/controllers/api/v2/system_errata_controller.rb +++ b/app/controllers/api/v2/system_errata_controller.rb @@ -30,7 +30,7 @@ def apply def find_system @system = System.first(:conditions => { :uuid => params[:system_id] }) - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? @system end end diff --git a/app/controllers/api/v2/system_packages_controller.rb b/app/controllers/api/v2/system_packages_controller.rb index 7a46dcbb4be..a7f28bd939b 100644 --- a/app/controllers/api/v2/system_packages_controller.rb +++ b/app/controllers/api/v2/system_packages_controller.rb @@ -85,7 +85,7 @@ def remove def find_system @system = System.first(:conditions => { :uuid => params[:system_id] }) - raise HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? + fail HttpErrors::NotFound, _("Couldn't find system '%s'") % params[:system_id] if @system.nil? @system end @@ -96,7 +96,7 @@ def valid_package_name?(package_name) def validate_package_list_format(packages) packages.each do |package| if !valid_package_name?(package) && !package.is_a?(Hash) - raise HttpErrors::BadRequest.new(_("%s is not a valid package name") % package) + fail HttpErrors::BadRequest.new(_("%s is not a valid package name") % package) end end @@ -105,17 +105,17 @@ def validate_package_list_format(packages) def require_packages_or_groups if params.slice(:packages, :groups).values.size != 1 - raise HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) + fail HttpErrors::BadRequest.new(_("Either packages or groups must be provided")) end end def require_packages_only if params[:groups] - raise HttpErrors::BadRequest.new(_("This action doesn't support pacakge groups")) + fail HttpErrors::BadRequest.new(_("This action doesn't support pacakge groups")) end unless params[:packages] - raise HttpErrors::BadRequest.new(_("Packages must be provided")) + fail HttpErrors::BadRequest.new(_("Packages must be provided")) end end diff --git a/app/controllers/api/v2/systems_bulk_actions_controller.rb b/app/controllers/api/v2/systems_bulk_actions_controller.rb index dc7a4080db4..5e59cf84563 100644 --- a/app/controllers/api/v2/systems_bulk_actions_controller.rb +++ b/app/controllers/api/v2/systems_bulk_actions_controller.rb @@ -54,9 +54,9 @@ def bulk_add_system_groups end if !invalid_perms.empty? - raise HttpErrors::BadRequest, _("Group membership modification is not allowed for system group(s): %s") % invalid_perms.join(', ') + fail HttpErrors::BadRequest, _("Group membership modification is not allowed for system group(s): %s") % invalid_perms.join(', ') elsif !max_systems_exceeded.empty? - raise HttpErrors::BadRequest, _("Maximum number of systems exceeded for system group(s): %s") % max_systems_exceeded.join(', ') + fail HttpErrors::BadRequest, _("Maximum number of systems exceeded for system group(s): %s") % max_systems_exceeded.join(', ') end @systems.each do |system| @@ -98,7 +98,7 @@ def bulk_remove_system_groups end if !invalid_perms.empty? - raise HttpErrors::BadRequest, _("Group membership modification is not allowed for system group(s): %s") % invalid_perms.join(', ') + fail HttpErrors::BadRequest, _("Group membership modification is not allowed for system group(s): %s") % invalid_perms.join(', ') end @systems.each do |system| @@ -128,11 +128,11 @@ def bulk_remove_system_groups param :content, Array, :desc => "List of content (e.g. package names, package group names or errata ids)", :required => true def install_content if params[:content_type].blank? - raise HttpErrors::BadRequest, _("A content_type must be provided.") + fail HttpErrors::BadRequest, _("A content_type must be provided.") end if params[:content].blank? - raise HttpErrors::BadRequest, _("No content has been provided.") + fail HttpErrors::BadRequest, _("No content has been provided.") else if params[:content_type].to_sym == :package @@ -160,11 +160,11 @@ def install_content param :content, Array, :desc => "List of content (e.g. package or package group names)", :required => true def update_content if params[:content_type].blank? - raise HttpErrors::BadRequest, _("A content_type must be provided.") + fail HttpErrors::BadRequest, _("A content_type must be provided.") end if params[:content].blank? - raise HttpErrors::BadRequest, _("No content has been provided.") + fail HttpErrors::BadRequest, _("No content has been provided.") else if params[:content_type].to_sym == :package @@ -195,11 +195,11 @@ def update_content param :content, Array, :desc => "List of content (e.g. package or package group names)", :required => true def remove_content if params[:content_type].blank? - raise HttpErrors::BadRequest, _("A content_type must be provided.") + fail HttpErrors::BadRequest, _("A content_type must be provided.") end if params[:content].blank? - raise HttpErrors::BadRequest, _("No content has been provided.") + fail HttpErrors::BadRequest, _("No content has been provided.") else if params[:content_type].to_sym == :package diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fc47085af6a..7ad758c1c63 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -54,7 +54,7 @@ class ApplicationController < ActionController::Base when :handle execute_rescue(exception) { |ex| render_error(ex) } when :raise - raise exception + fail exception end end @@ -269,14 +269,14 @@ def verify_ldap def require_org unless session && current_organization execute_after_filters - raise Errors::SecurityViolation, _("User does not belong to an organization.") + fail Errors::SecurityViolation, _("User does not belong to an organization.") end end # TODO: this check can be removed once we start deleting sessions during org deletion def check_deleted_org if current_organization && current_organization.being_deleted? - raise Errors::SecurityViolation, _("Current organization is being deleted, switch to a different one.") + fail Errors::SecurityViolation, _("Current organization is being deleted, switch to a different one.") end end diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index f0a181d7f55..534dace8c6d 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -140,7 +140,7 @@ def update end if params[:state] - raise _('Invalid state') if !%w(review new).index(params[:state]) + fail _('Invalid state') if !%w(review new).index(params[:state]) if send_changeset to_ret = {} to_ret[:changeset] = simplify_changeset(@changeset) if send_changeset diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index e5fcb644535..fdc42450384 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -75,7 +75,7 @@ def details def lookup_package @package_id = params[:id] @package = Package.find @package_id - raise _("Unable to find package %s") % @package_id if @package.nil? + fail _("Unable to find package %s") % @package_id if @package.nil? end def find_filter diff --git a/app/controllers/systems_controller.rb b/app/controllers/systems_controller.rb index b7f954a9ca3..ef7e244aac7 100644 --- a/app/controllers/systems_controller.rb +++ b/app/controllers/systems_controller.rb @@ -464,7 +464,7 @@ def bulk_remove_system_group groups_info[system_group.id] = system_group.name end if !invalid_perms.empty? - raise _("System Group membership modification not allowed for group(s): %s") % invalid_perms.join(', ') + fail _("System Group membership modification not allowed for group(s): %s") % invalid_perms.join(', ') end @systems.each do |system| diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 851e5076331..bcd589d9ce4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -253,7 +253,7 @@ def update_environment return end - raise no_env_available_msg if default_environment_id.nil? && params['org_id'].present? + fail no_env_available_msg if default_environment_id.nil? && params['org_id'].present? @environment = default_environment_id.nil? ? nil : KTEnvironment.find(default_environment_id) @user.default_environment = @environment diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4c365ebf545..95b1c2e3b95 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -79,7 +79,7 @@ def two_panel(collection, options) enable_create = true if enable_create.nil? enable_sort = options[:enable_sort] ? options[:enable_sort] : false - raise ":titles option not provided" unless options[:titles] + fail ":titles option not provided" unless options[:titles] render :partial => "common/panel", :locals => { diff --git a/app/helpers/experimental/katello_form_builder.rb b/app/helpers/experimental/katello_form_builder.rb index b2c33d6bb9b..545f1d75638 100644 --- a/app/helpers/experimental/katello_form_builder.rb +++ b/app/helpers/experimental/katello_form_builder.rb @@ -111,7 +111,7 @@ def base(name, *args) options.symbolize_keys! options[:grid] ||= [2, 5] unless options[:grid].is_a?(Array) && options[:grid].size == 2 - raise ArgumentError, "#{name}[grid]: expecting array of size 2" + fail ArgumentError, "#{name}[grid]: expecting array of size 2" end # check if user added some class for wrappers and add grid and align classes diff --git a/app/helpers/katello_form_builder.rb b/app/helpers/katello_form_builder.rb index 8e899ed842c..15834a8595b 100644 --- a/app/helpers/katello_form_builder.rb +++ b/app/helpers/katello_form_builder.rb @@ -105,7 +105,7 @@ def base(name, *args) options.symbolize_keys! options[:grid] ||= [2, 5] unless options[:grid].is_a?(Array) && options[:grid].size == 2 - raise ArgumentError, "#{name}[grid]: expecting array of size 2" + fail ArgumentError, "#{name}[grid]: expecting array of size 2" end # check if user added some class for wrappers and add grid and align classes [:label_wrapper, :input_wrapper].each_with_index do |wrapper, i| diff --git a/app/lib/api/v1/error_handling.rb b/app/lib/api/v1/error_handling.rb index ce1467c6e5b..9d9aa5b2b58 100644 --- a/app/lib/api/v1/error_handling.rb +++ b/app/lib/api/v1/error_handling.rb @@ -94,7 +94,7 @@ def rescue_from_record_invalid(exception) when ActiveRecord::RecordInvalid exception.record.errors else - raise ArgumentError.new("ActiveRecord::RecordInvalid exception.") + fail ArgumentError.new("ActiveRecord::RecordInvalid exception.") end errors.messages.each_pair do |c, e| diff --git a/app/lib/api/v2/error_handling.rb b/app/lib/api/v2/error_handling.rb index 5e1cd30cd1b..173eb0d85eb 100644 --- a/app/lib/api/v2/error_handling.rb +++ b/app/lib/api/v2/error_handling.rb @@ -93,7 +93,7 @@ def rescue_from_record_invalid(exception) when ActiveRecord::RecordInvalid exception.record.errors else - raise ArgumentError.new("ActiveRecord::RecordInvalid exception.") + fail ArgumentError.new("ActiveRecord::RecordInvalid exception.") end errors.messages.each_pair do |c, e| diff --git a/app/lib/authorization_rules.rb b/app/lib/authorization_rules.rb index 06bc5f7a61b..de3515dbc6f 100644 --- a/app/lib/authorization_rules.rb +++ b/app/lib/authorization_rules.rb @@ -20,7 +20,7 @@ def self.included(base) # authorize the user for the requested action def authorize(ctrl = params[:controller], action = self.action_name) user = current_user - raise StandardError, "Current user not set" unless user + fail StandardError, "Current user not set" unless user logger.debug "Authorizing #{current_user.username} for #{ctrl}/#{action}" allowed = false @@ -28,11 +28,11 @@ def authorize(ctrl = params[:controller], action = self.action_name) allowed = rule_set[action].call if rule_set[action].is_a?(Proc) allowed = user.allowed_to?(*rule_set[action]) if rule_set[action].is_a?(Array) return true if allowed - raise Errors::SecurityViolation, "User #{current_user.username} is not allowed to access #{params[:controller]}/#{params[:action]}" + fail Errors::SecurityViolation, "User #{current_user.username} is not allowed to access #{params[:controller]}/#{params[:action]}" end def rules - raise Errors::SecurityViolation, "Rules not defined for #{current_user.username} for #{params[:controller]}/#{params[:action]}" + fail Errors::SecurityViolation, "Rules not defined for #{current_user.username} for #{params[:controller]}/#{params[:action]}" end # TODO: should be moved out of authorization module @@ -54,7 +54,7 @@ def params_match(ctrl = params[:controller], action = self.action_name) end return true if bad_params.empty? - raise HttpErrors::UnprocessableEntity.new(build_bad_params_error_msg(bad_params, params)) + fail HttpErrors::UnprocessableEntity.new(build_bad_params_error_msg(bad_params, params)) end def build_bad_params_error_msg(bad_params, params) diff --git a/app/lib/content_search/element.rb b/app/lib/content_search/element.rb index 2c471e670f9..96559c3713f 100644 --- a/app/lib/content_search/element.rb +++ b/app/lib/content_search/element.rb @@ -28,7 +28,7 @@ def display_attributes def as_json(options = {}) json = {} - raise "Display attributes not defined for #{self.class.name}" if display_attributes.nil? || display_attributes.empty? + fail "Display attributes not defined for #{self.class.name}" if display_attributes.nil? || display_attributes.empty? display_attributes.each do |attr| json[attr] = self.send(attr) if self.send(attr) end diff --git a/app/lib/glue/task.rb b/app/lib/glue/task.rb index af0e1b0b76e..ae383bad4e3 100644 --- a/app/lib/glue/task.rb +++ b/app/lib/glue/task.rb @@ -28,7 +28,7 @@ def status=(s) update_ts @status = s else - raise "invalid STATE #{s}" + fail "invalid STATE #{s}" end end diff --git a/app/lib/http_resource.rb b/app/lib/http_resource.rb index 0b91653a4fa..d6c456a0760 100644 --- a/app/lib/http_resource.rb +++ b/app/lib/http_resource.rb @@ -46,7 +46,7 @@ def []=(key, value) class << self # children must redefine def logger - raise NotImplementedError + fail NotImplementedError end def process_response(resp) @@ -70,7 +70,7 @@ def process_response(resp) raise NetworkException, [resp.code.to_s, resp.body].reject{|s| s.nil? || s.empty?}.join(' ') end end - raise RestClientException, {:message => message, :service_code => service_code, :code => status_code}, caller + fail RestClientException, {:message => message, :service_code => service_code, :code => status_code}, caller end def print_debug_info(a_path, headers = {}, payload = {}) @@ -99,7 +99,7 @@ def get(a_path, headers = {}) raise_rest_client_exception e, a_path, "GET" rescue Errno::ECONNREFUSED service = a_path.split("/").second - raise Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize + fail Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize end def post(a_path, payload = {}, headers = {}) @@ -113,7 +113,7 @@ def post(a_path, payload = {}, headers = {}) raise_rest_client_exception e, a_path, "POST" rescue Errno::ECONNREFUSED service = a_path.split("/").second - raise Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize + fail Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize end def put(a_path, payload = {}, headers = {}) @@ -127,7 +127,7 @@ def put(a_path, payload = {}, headers = {}) raise_rest_client_exception e, a_path, "PUT" rescue Errno::ECONNREFUSED service = a_path.split("/").second - raise Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize + fail Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize end def delete(a_path = nil, headers = {}) @@ -141,7 +141,7 @@ def delete(a_path = nil, headers = {}) raise_rest_client_exception e, a_path, "DELETE" rescue Errno::ECONNREFUSED service = a_path.split("/").second - raise Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize + fail Errors::ConnectionRefusedException, _("A backend service [ %s ] is unreachable") % service.capitalize end # re-raise the same exception with nicer error message @@ -153,7 +153,7 @@ def raise_rest_client_exception(e, a_path, http_method) msg end end - raise e + fail e end def join_path(*args) diff --git a/app/lib/kt_locale.rb b/app/lib/kt_locale.rb index e2154c9f6c9..b2d09616cc2 100644 --- a/app/lib/kt_locale.rb +++ b/app/lib/kt_locale.rb @@ -63,7 +63,7 @@ def parse_accept_locale l.split(';q=') end locale_lang = locale_lang.sort do |x, y| - raise "incorrect locale format" unless x.first =~ /^[a-z\-]+$/i + fail "incorrect locale format" unless x.first =~ /^[a-z\-]+$/i y.last.to_f <=> x.last.to_f end locale_lang.collect do |l| diff --git a/app/lib/lazy_accessor.rb b/app/lib/lazy_accessor.rb index 9a746515216..f27d0440c03 100644 --- a/app/lib/lazy_accessor.rb +++ b/app/lib/lazy_accessor.rb @@ -29,12 +29,12 @@ def lazy_accessor(*args) options = args.extract_options! @lazy_attributes = [] if @lazy_attributes.nil? @lazy_attributes = @lazy_attributes.concat args - raise ArgumentError, "Attribute names must be symbols" if args.any?{ |attribute| !attribute.is_a?(Symbol) } + fail ArgumentError, "Attribute names must be symbols" if args.any?{ |attribute| !attribute.is_a?(Symbol) } redefined_attr = args.find{ |attribute| instance_methods.include?(attribute.to_s) } Rails.logger.warn "Remote attribute '#{redefined_attr}' has already been defined" if redefined_attr initializer = options[:initializer] - raise ArgumentError, "Please provide an initializer" if initializer.nil? + fail ArgumentError, "Please provide an initializer" if initializer.nil? args.each do |symbol| send :define_method, "#{symbol.to_s}_will_change!" do @@ -137,7 +137,7 @@ def remote_attribute_value(attr, initializer, in_group) def run_initializer(in_group, initializer) remote_values = self.instance_eval(&initializer) if in_group && !remote_values.is_a?(Hash) - raise RuntimeError.new("Expect initializer to return hash if a group of attributes is defined by lazy_accessor") + fail RuntimeError.new("Expect initializer to return hash if a group of attributes is defined by lazy_accessor") end remote_values end diff --git a/app/lib/notifications/controller_helper.rb b/app/lib/notifications/controller_helper.rb index c77783919d6..75a89d4c0a9 100644 --- a/app/lib/notifications/controller_helper.rb +++ b/app/lib/notifications/controller_helper.rb @@ -36,6 +36,6 @@ def notify # { :organization => nil } # end def default_notify_options - raise NotImplementedError + fail NotImplementedError end end diff --git a/app/lib/notifications/notifier.rb b/app/lib/notifications/notifier.rb index 87785cd04a1..8f0cfa45a21 100644 --- a/app/lib/notifications/notifier.rb +++ b/app/lib/notifications/notifier.rb @@ -169,19 +169,19 @@ def process_options(options) options.assert_valid_keys(*default_options.keys) - raise ArgumentError, "unknown notice level #{options[:level].inspect}" unless LEVELS.include? options[:level] + fail ArgumentError, "unknown notice level #{options[:level].inspect}" unless LEVELS.include? options[:level] unless SEND_AS_OPTIONS.include? options[:send_as] - raise ArgumentError, "unknown send as #{options[:send_as].inspect}" + fail ArgumentError, "unknown send as #{options[:send_as].inspect}" end [:asynchronous, :persist, :global].each do |flag| - raise ArgumentError, + fail ArgumentError, "#{flag} has to be true || false, but is #{options[flag].inspect}" unless FLAGS.include? options[flag] end - raise ArgumentError, "cannot be asynchronous without persist" if options[:asynchronous] && !options[:persist] - raise ArgumentError, "cannot use details without persist" if options[:details] && !options[:persist] + fail ArgumentError, "cannot be asynchronous without persist" if options[:asynchronous] && !options[:persist] + fail ArgumentError, "cannot use details without persist" if options[:details] && !options[:persist] return options end diff --git a/app/lib/repo_discovery.rb b/app/lib/repo_discovery.rb index 7358c094459..dbe9c626f6a 100644 --- a/app/lib/repo_discovery.rb +++ b/app/lib/repo_discovery.rb @@ -29,7 +29,7 @@ def run(found_lambda, continue_lambda) elsif %w(http https).include?(@uri.scheme) http_crawl(found_lambda, continue_lambda) else - raise _("Unsupported URL protocol %s.") % @uri.scheme + fail _("Unsupported URL protocol %s.") % @uri.scheme end end diff --git a/app/lib/resources/candlepin.rb b/app/lib/resources/candlepin.rb index f51dc9cc25f..8ef645c1ddb 100644 --- a/app/lib/resources/candlepin.rb +++ b/app/lib/resources/candlepin.rb @@ -479,7 +479,7 @@ class Pool < CandlepinResource class << self def find(pool_id) pool_json = self.get(path(pool_id), self.default_headers).body - raise ArgumentError, "pool id cannot contain ?" if pool_id["?"] + fail ArgumentError, "pool id cannot contain ?" if pool_id["?"] JSON.parse(pool_json).with_indifferent_access end @@ -489,7 +489,7 @@ def get_for_owner(owner_key) end def destroy(id) - raise ArgumentError, "pool id has to be specified" unless id + fail ArgumentError, "pool id has to be specified" unless id self.delete(path(id), self.default_headers).code.to_i end @@ -521,7 +521,7 @@ def all end def destroy(id) - raise ArgumentError, "content id has to be specified" unless id + fail ArgumentError, "content id has to be specified" unless id self.delete(path(id), self.default_headers).code.to_i end @@ -539,7 +539,7 @@ class Subscription < CandlepinResource class << self def destroy(subscription_id) - raise ArgumentError, "subscription id has to be specified" unless subscription_id + fail ArgumentError, "subscription id has to be specified" unless subscription_id self.delete(path(subscription_id), self.default_headers).code.to_i end @@ -632,7 +632,7 @@ def key(id, owner) end def destroy(product_id) - raise ArgumentError, "product id has to be specified" unless product_id + fail ArgumentError, "product id has to be specified" unless product_id self.delete(path(product_id), self.default_headers).code.to_i end diff --git a/app/lib/resources/cdn.rb b/app/lib/resources/cdn.rb index 779b0d7e261..cd83d261b5d 100644 --- a/app/lib/resources/cdn.rb +++ b/app/lib/resources/cdn.rb @@ -63,7 +63,7 @@ def initialize(url, options = {}) @net.verify_callback = lambda do |preverify_ok, ssl_context| if (!preverify_ok) || ssl_context.error != 0 err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})" - raise RestClient::SSLCertificateNotVerified.new(err_msg) + fail RestClient::SSLCertificateNotVerified.new(err_msg) end true end @@ -95,13 +95,13 @@ def get(path, headers = {}) rescue EOFError raise RestClient::ServerBrokeConnection rescue Timeout::Error - raise RestClient::RequestTimeout + fail RestClient::RequestTimeout rescue RestClient::ResourceNotFound - raise Errors::NotFound.new(_("CDN loading error: %s not found") % used_url) + fail Errors::NotFound.new(_("CDN loading error: %s not found") % used_url) rescue RestClient::Unauthorized - raise Errors::SecurityViolation.new(_("CDN loading error: access denied to %s") % used_url) + fail Errors::SecurityViolation.new(_("CDN loading error: access denied to %s") % used_url) rescue RestClient::Forbidden - raise Errors::SecurityViolation.new(_("CDN loading error: access forbidden to %s") % used_url) + fail Errors::SecurityViolation.new(_("CDN loading error: access forbidden to %s") % used_url) end end diff --git a/app/lib/util/data.rb b/app/lib/util/data.rb index adac0c17cd3..d79c9821242 100644 --- a/app/lib/util/data.rb +++ b/app/lib/util/data.rb @@ -33,7 +33,7 @@ def self.ostructize(obj, options = {}) new_key = key end - raise RuntimeError.new("Error occured while converting Hash to OpenStruct. " + + fail RuntimeError.new("Error occured while converting Hash to OpenStruct. " + "Key '%s' conflicts with method OpenStruct#%s." % [new_key, new_key]) if Object.respond_to? new_key ostructized_hash[new_key] = ostructize(value, options) diff --git a/app/lib/util/thread_session.rb b/app/lib/util/thread_session.rb index 39f0cb5a354..82b1555b027 100644 --- a/app/lib/util/thread_session.rb +++ b/app/lib/util/thread_session.rb @@ -49,7 +49,7 @@ def self.current def self.current=(o) unless (o.nil? || o.is_a?(self) || o.class.name == 'RSpec::Mocks::Mock') - raise(ArgumentError, "Unable to set current User, expected class '#{self}', got #{o.inspect}") + fail(ArgumentError, "Unable to set current User, expected class '#{self}', got #{o.inspect}") end username = o.is_a?(User) ? o.username : 'nil' Rails.logger.debug "Setting current user thread-local variable to " + username @@ -88,7 +88,7 @@ def self.current=(o) def self.as(username, &do_block) old_user = current self.current = User.find_by_username(username) - raise(ArgumentError, "Cannot find user '%s'" % username) if self.current.nil? + fail(ArgumentError, "Cannot find user '%s'" % username) if self.current.nil? do_block.call ensure self.current = old_user diff --git a/app/models/activation_key.rb b/app/models/activation_key.rb index 8a735dceff8..6a762440a3d 100644 --- a/app/models/activation_key.rb +++ b/app/models/activation_key.rb @@ -71,7 +71,7 @@ def usage_count # sets up system when registering with this activation key - must be executed in a transaction def apply_to_system(system) if !usage_limit.nil? && usage_limit != -1 && usage_count >= usage_limit - raise Errors::UsageLimitExhaustedException, _("Usage limit (%{limit}) exhausted for activation key '%{name}'") % {:limit => usage_limit, :name => name} + fail Errors::UsageLimitExhaustedException, _("Usage limit (%{limit}) exhausted for activation key '%{name}'") % {:limit => usage_limit, :name => name} end system.environment_id = self.environment_id if self.environment_id system.content_view_id = self.content_view_id if self.content_view_id diff --git a/app/models/async_operation.rb b/app/models/async_operation.rb index 7e299ad1ccd..e5f237b003a 100644 --- a/app/models/async_operation.rb +++ b/app/models/async_operation.rb @@ -14,7 +14,7 @@ #delegate :method, :to => :object def initialize(status_id, username, object, method_name, args) - raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true) + fail NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true) self.status_id = status_id self.username = username diff --git a/app/models/authorization/content_view.rb b/app/models/authorization/content_view.rb index 4d05ff4d5a0..845ac187f5c 100644 --- a/app/models/authorization/content_view.rb +++ b/app/models/authorization/content_view.rb @@ -88,7 +88,7 @@ def subscribable(org) end def items(org, verbs) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? resource = :content_views if Katello.config.katello? diff --git a/app/models/authorization/content_view_definition.rb b/app/models/authorization/content_view_definition.rb index 14aa4d70716..13d1b6427fd 100644 --- a/app/models/authorization/content_view_definition.rb +++ b/app/models/authorization/content_view_definition.rb @@ -87,7 +87,7 @@ def creatable?(org) end def items(org, verbs) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? resource = :content_view_definitions if User.allowed_all_tags?(verbs, resource, org) where(:organization_id => org.id) diff --git a/app/models/authorization/content_view_version.rb b/app/models/authorization/content_view_version.rb index f6545fde8fa..c445cbff92a 100644 --- a/app/models/authorization/content_view_version.rb +++ b/app/models/authorization/content_view_version.rb @@ -24,7 +24,7 @@ def promotable(org) end def items(org, verbs) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? resource = :content_views if User.allowed_all_tags?(verbs, resource, org) diff --git a/app/models/authorization/distributor.rb b/app/models/authorization/distributor.rb index 1867f822d35..29470739aed 100644 --- a/app/models/authorization/distributor.rb +++ b/app/models/authorization/distributor.rb @@ -20,7 +20,7 @@ def list_tags end def readable(org) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? if org.distributors_readable? where(:environment_id => org.environment_ids) #list all distributors in an org else #just list for environments the user can access diff --git a/app/models/authorization/enforcement.rb b/app/models/authorization/enforcement.rb index 2051fe91657..7eb896a5773 100644 --- a/app/models/authorization/enforcement.rb +++ b/app/models/authorization/enforcement.rb @@ -18,7 +18,7 @@ def self.included(base) # on the current logged user. The class attribute User.current must be set! def self.allowed_all_tags?(verb, resource_type = nil, org = nil) u = User.current - raise Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) + fail Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) u.allowed_all_tags?(verb, resource_type, org) end @@ -27,7 +27,7 @@ def self.allowed_all_tags?(verb, resource_type = nil, org = nil) def self.allowed_tags_sql(verb, resource_type = nil, org = nil) ResourceType.check resource_type, verb u = User.current - raise Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) + fail Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) u.allowed_tags_sql(verb, resource_type, org) end @@ -35,7 +35,7 @@ def self.allowed_tags_sql(verb, resource_type = nil, org = nil) # on the current logged user. The class attribute User.current must be set! def self.allowed_to?(verb, resource_type, tags = nil, org = nil, any_tags = false) u = User.current - raise Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) + fail Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) u.allowed_to?(verb, resource_type, tags, org, any_tags) end @@ -43,11 +43,11 @@ def self.allowed_to?(verb, resource_type, tags = nil, org = nil, any_tags = fals # SecurityViolation exception leading to the denial page. def self.allowed_to_or_error?(verb, resource_type, tags = nil, org = nil, any_tags = false) u = User.current - raise Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) + fail Errors::UserNotSet, "current user is not set" if u.nil? || !u.is_a?(User) unless u.allowed_to?(verb, resource_type, tags, org, any_tags) msg = "User #{u.username} is not allowed to #{verb} in #{resource_type} using #{tags}" Rails.logger.error msg - raise Errors::SecurityViolation, msg + fail Errors::SecurityViolation, msg end end @@ -114,7 +114,7 @@ def allowed_to?(verbs, resource_type, tags = nil, org = nil, any_tags = false) tags = [] if tags.nil? tags = tags.is_a?(Array) ? tags.clone : [tags] if tags.detect { |tag| !(tag.is_a?(Numeric) || (tag.is_a?(String) && tag.to_s =~ /^\d+$/)) } - raise ArgumentError, "Tags need to be integers - #{tags} are not." + fail ArgumentError, "Tags need to be integers - #{tags} are not." end ResourceType.check resource_type, verbs verbs = [] if verbs.nil? diff --git a/app/models/authorization/environment.rb b/app/models/authorization/environment.rb index 1910a570126..1a303d7ca09 100644 --- a/app/models/authorization/environment.rb +++ b/app/models/authorization/environment.rb @@ -71,7 +71,7 @@ def any_contents_readable?(org, skip_library = false) end def authorized_items(org, verbs, resource = :environments) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? if User.allowed_all_tags?(verbs, resource, org) where(:organization_id => org) else diff --git a/app/models/authorization/provider.rb b/app/models/authorization/provider.rb index 08c20c19322..341c83bdf40 100644 --- a/app/models/authorization/provider.rb +++ b/app/models/authorization/provider.rb @@ -69,7 +69,7 @@ def list_verbs(global = false) end def items(org, verbs) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? resource = :providers if (Katello.config.katello? && verbs.include?(:read) && org.syncable?) || User.allowed_all_tags?(verbs, resource, org) where(:organization_id => org) diff --git a/app/models/authorization/system.rb b/app/models/authorization/system.rb index ddf310eea32..9cae676b96a 100644 --- a/app/models/authorization/system.rb +++ b/app/models/authorization/system.rb @@ -20,7 +20,7 @@ def list_tags end def readable(org) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? if org.systems_readable? where(:environment_id => org.environment_ids) #list all systems in an org else #just list for environments the user can access diff --git a/app/models/authorization/system_group.rb b/app/models/authorization/system_group.rb index 4ad5570ddac..f4f56a357a1 100644 --- a/app/models/authorization/system_group.rb +++ b/app/models/authorization/system_group.rb @@ -74,7 +74,7 @@ def no_tag_verbs end def items(org, verbs) - raise "scope requires an organization" if org.nil? + fail "scope requires an organization" if org.nil? resource = :system_groups if ::User.allowed_all_tags?(verbs, resource, org) where(:organization_id => org) diff --git a/app/models/candlepin/product_content.rb b/app/models/candlepin/product_content.rb index 1e57cd4e8e7..e057248cb26 100644 --- a/app/models/candlepin/product_content.rb +++ b/app/models/candlepin/product_content.rb @@ -51,7 +51,7 @@ def can_disable? end def disable - raise _("One or more repositories are still enabled for this content set.") unless self.can_disable? + fail _("One or more repositories are still enabled for this content set.") unless self.can_disable? repos = self.product.repos(self.product.organization.library, true).where(:content_id => self.content.id) repos.each do |repo| repo.destroy diff --git a/app/models/changeset.rb b/app/models/changeset.rb index afa7a14edd4..c4c7b664487 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -69,7 +69,7 @@ def self.new_changeset(args) end def self.changeset_class(args) - raise "Must provide a changeset type." unless type = args.try(:[], :type) + fail "Must provide a changeset type." unless type = args.try(:[], :type) type.downcase! if type == PROMOTION @@ -77,7 +77,7 @@ def self.changeset_class(args) elsif type == DELETION return DeletionChangeset else - raise _("Unknown changeset type. Choose one of: %s") % TYPES.join(", ") + fail _("Unknown changeset type. Choose one of: %s") % TYPES.join(", ") end end @@ -109,13 +109,13 @@ def in_review? def check_review_state! if !in_review? - raise _("Cannot apply the changeset '%s' because it is not in the review phase.") % self.name + fail _("Cannot apply the changeset '%s' because it is not in the review phase.") % self.name end end def check_collisions! if (collision = Changeset.started.colliding(self).first) - raise _("Cannot apply the changeset '%{changeset}' while another colliding changeset (%{another_changeset}) is being applied.") % + fail _("Cannot apply the changeset '%{changeset}' while another colliding changeset (%{another_changeset}) is being applied.") % { :changeset => self.name, :another_changeset => collision.name } end end @@ -130,10 +130,10 @@ def self.create_for(acct_type, options) def add_content_view!(view, include_components = false) unless env_to_verify_on_add_content.content_views.include?(view) - raise Errors::ChangesetContentException.new(_("Content view not found within environment you want to promote from.")) + fail Errors::ChangesetContentException.new(_("Content view not found within environment you want to promote from.")) end if promotion? && content_view_in_environment?(view) - raise Errors::ChangesetContentException.new( + fail Errors::ChangesetContentException.new( _("Cannot add content view '%{view}' to changeset. View version already in environment '%{env}'.") % {:view => view.name, :env => environment.name}) end @@ -170,7 +170,7 @@ def as_json(options = nil) protected def validate_content!(elements) - elements.each { |e| raise ActiveRecord::RecordInvalid.new(e) if !e.valid? } + elements.each { |e| fail ActiveRecord::RecordInvalid.new(e) if !e.valid? } end def validate_content_view_tasks_complete! @@ -181,7 +181,7 @@ def validate_content_view_tasks_complete! self.content_views.each do |view| version = view.version(from_env) if version.try(:task_status).try(:pending?) - raise Errors::ContentViewTaskInProgress.new(_("A '%{type_of_action}' action is currently in progress for "\ + fail Errors::ContentViewTaskInProgress.new(_("A '%{type_of_action}' action is currently in progress for "\ "content view '%{content_view}'. Please retry the changeset "\ "after the action completes.") % { :type_of_action => _(TaskStatus::TYPES[version.task_status.task_type][:english_name]), @@ -190,7 +190,7 @@ def validate_content_view_tasks_complete! view.content_view_definition.component_content_views.each do |component_view| version = component_view.version(from_env) if version.task_status.pending? - raise Errors::ContentViewTaskInProgress.new(_("A '%{type_of_action}' action is currently in progress for "\ + fail Errors::ContentViewTaskInProgress.new(_("A '%{type_of_action}' action is currently in progress for "\ "component content view '%{content_view}'. Please retry "\ "the changeset after the action completes.") % { :type_of_action => _(TaskStatus::TYPES[version.task_status.task_type][:english_name]), diff --git a/app/models/content_view.rb b/app/models/content_view.rb index ad763659753..6ea13bdfa3d 100644 --- a/app/models/content_view.rb +++ b/app/models/content_view.rb @@ -202,7 +202,7 @@ def promote_via_changeset(env, apply_options = {:async => true}, end def promote(from_env, to_env) - raise "Cannot promote from #{from_env.name}, view does not exist there." if !self.environments.include?(from_env) + fail "Cannot promote from #{from_env.name}, view does not exist there." if !self.environments.include?(from_env) replacing_version = self.version(to_env) @@ -234,11 +234,11 @@ def promote(from_env, to_env) def delete(from_env) if from_env.library? && in_non_library_environment? - raise Errors::ChangesetContentException.new(_("Cannot delete view while it exits in environments")) + fail Errors::ChangesetContentException.new(_("Cannot delete view while it exits in environments")) end version = self.version(from_env) if version.nil? - raise Errors::ChangesetContentException.new(_("Cannot delete from %s, view does not exist there.") % from_env.name) + fail Errors::ChangesetContentException.new(_("Cannot delete from %s, view does not exist there.") % from_env.name) end version = ContentViewVersion.find(version.id) Glue::Event.trigger(Katello::Actions::ContentViewDemote, self, from_env) diff --git a/app/models/content_view_definition_base.rb b/app/models/content_view_definition_base.rb index 4b3d31692cb..6eb545d1b6f 100644 --- a/app/models/content_view_definition_base.rb +++ b/app/models/content_view_definition_base.rb @@ -117,15 +117,15 @@ def validate_component_views(view) library_repos = component_content_views.map(&:library_repos).flatten + view.library_repos library_repo_ids = library_repos.map(&:id) if library_repo_ids.length != library_repo_ids.uniq.length - raise Errors::ContentViewRepositoryOverlap.new(_("Definition cannot contain views with the same repositories.")) + fail Errors::ContentViewRepositoryOverlap.new(_("Definition cannot contain views with the same repositories.")) end if library_repos.select(&:puppet?).length > 1 - raise Errors::ContentViewDefinitionBadContent.new(_("Definition cannot more than one view with a puppet repository.")) + fail Errors::ContentViewDefinitionBadContent.new(_("Definition cannot more than one view with a puppet repository.")) end if !self.composite? - raise Errors::ContentViewDefinitionBadContent.new(_("Definition cannot contain views if not composite definition")) + fail Errors::ContentViewDefinitionBadContent.new(_("Definition cannot contain views if not composite definition")) end end end @@ -134,7 +134,7 @@ def validate_repos(repo) if type == "ContentViewDefinition" # TODO: check composite views if repositories.select(&:puppet?).length > 0 && repo.puppet? - raise Errors::ContentViewRepositoryOverlap.new(_("Definition cannot contain more than one Puppet repository.")) + fail Errors::ContentViewRepositoryOverlap.new(_("Definition cannot contain more than one Puppet repository.")) end end end diff --git a/app/models/content_view_version.rb b/app/models/content_view_version.rb index 2ee34f070bd..c0b0202cb55 100644 --- a/app/models/content_view_version.rb +++ b/app/models/content_view_version.rb @@ -168,7 +168,7 @@ def deletable?(from_env) def delete(from_env) unless deletable?(from_env) - raise Errors::ChangesetContentException.new(_("Cannot delete view %{view} from %{env}, systems are currently subscribed. " + + fail Errors::ChangesetContentException.new(_("Cannot delete view %{view} from %{env}, systems are currently subscribed. " + "Please move subscribed systems to another content view or environment.") % {:env => from_env.name, :view => self.content_view.name}) end diff --git a/app/models/content_view_version_environment.rb b/app/models/content_view_version_environment.rb index 9e301928208..0c25e3f0d92 100644 --- a/app/models/content_view_version_environment.rb +++ b/app/models/content_view_version_environment.rb @@ -18,7 +18,7 @@ class ContentViewVersionEnvironment < ActiveRecord::Base def verify_not_exists if self.content_view_version.environments.include?(self.environment) - raise _("Content View %{view} is already in environment %{env}") % {:view => self.content_view_version.content_view.name, :env => self.environment.name} + fail _("Content View %{view} is already in environment %{env}") % {:view => self.content_view_version.content_view.name, :env => self.environment.name} end end diff --git a/app/models/custom_info.rb b/app/models/custom_info.rb index 23d63d95d4c..7f66584a9d6 100644 --- a/app/models/custom_info.rb +++ b/app/models/custom_info.rb @@ -36,7 +36,7 @@ def self.find_by_informable_keyname(informable, keyname) def self.find_informable(informable_type, informable_id) class_name = informable_type.classify informable = class_name.constantize.find(informable_id) - raise _("Resource %s does not support custom information") % class_name unless informable.respond_to? :custom_info + fail _("Resource %s does not support custom information") % class_name unless informable.respond_to? :custom_info return informable end diff --git a/app/models/filter_rule.rb b/app/models/filter_rule.rb index 35f2d0111c0..b31df951fe9 100644 --- a/app/models/filter_rule.rb +++ b/app/models/filter_rule.rb @@ -58,7 +58,7 @@ def self.class_for(content_type) PuppetModuleRule else params = {:content_type => content_type, :content_types => CONTENT_TYPES.join(", ")} - raise _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") % params + fail _("Invalid content type '%{content_type}' provided. Content types can be one of %{content_types}") % params end end diff --git a/app/models/glue.rb b/app/models/glue.rb index 428de783d06..79d79d33d3e 100644 --- a/app/models/glue.rb +++ b/app/models/glue.rb @@ -63,7 +63,7 @@ def rollback Glue.logger.warning "Rollback initiated" Glue.logger.warning "Before rollback pre-queue: #{pre_queue.to_log}" Glue.logger.warning "Before rollback post-queue: #{post_queue.to_log}" - raise ActiveRecord::Rollback + fail ActiveRecord::Rollback end def pre_queue @@ -167,7 +167,7 @@ def execute(opts = {}) when /del/ met.gsub!("del", "set") else - raise "Dont know how to rollback #{met}" + fail "Dont know how to rollback #{met}" end met = met.to_sym end @@ -175,7 +175,7 @@ def execute(opts = {}) if obj.respond_to?(met) return args.empty? ? obj.send(met) : obj.send(met, *args) else - raise Errors::OrchestrationException.new("invalid method #{met}") + fail Errors::OrchestrationException.new("invalid method #{met}") end end diff --git a/app/models/glue/candlepin/.rubocop.yml b/app/models/glue/candlepin/.rubocop.yml index 1039c7081a3..ec8a34afebb 100644 --- a/app/models/glue/candlepin/.rubocop.yml +++ b/app/models/glue/candlepin/.rubocop.yml @@ -5,4 +5,7 @@ inherit_from: - ../../../../.rubocop.yml SymbolName: + Enabled: false + +VariableName: Enabled: false \ No newline at end of file diff --git a/app/models/glue/candlepin/consumer.rb b/app/models/glue/candlepin/consumer.rb index a862294dff5..52ec7c0aa2d 100644 --- a/app/models/glue/candlepin/consumer.rb +++ b/app/models/glue/candlepin/consumer.rb @@ -153,7 +153,7 @@ def del_candlepin_consumer true rescue => e Rails.logger.error "Failed to delete candlepin consumer #{name}: #{e}, #{e.backtrace.join("\n")}" - raise e + fail e end def regenerate_identity_certificates diff --git a/app/models/glue/candlepin/content.rb b/app/models/glue/candlepin/content.rb index fd5060c160d..ca845b43157 100644 --- a/app/models/glue/candlepin/content.rb +++ b/app/models/glue/candlepin/content.rb @@ -102,7 +102,7 @@ def update_content def create_content #only used for custom content - raise 'Can only create content for custom providers' if self.product.provider.redhat_provider? + fail 'Can only create content for custom providers' if self.product.provider.redhat_provider? new_content = ::Candlepin::ProductContent.new({ :content => { :name => self.name, diff --git a/app/models/glue/candlepin/environment.rb b/app/models/glue/candlepin/environment.rb index 191c7e40286..56897f41feb 100644 --- a/app/models/glue/candlepin/environment.rb +++ b/app/models/glue/candlepin/environment.rb @@ -37,7 +37,7 @@ def set_environment rescue => e Rails.logger.error _("Failed to create candlepin environment %s") % "#{self.label}: #{e}, #{e.backtrace.join("\n")}" - raise e + fail e end def candlepin_info @@ -58,7 +58,7 @@ def del_environment rescue => e Rails.logger.error _("Failed to delete candlepin environment %s") % "#{self.label}: #{e}, #{e.backtrace.join("\n")}" - raise e + fail e end def save_environment_orchestration diff --git a/app/models/glue/elastic_search/errata.rb b/app/models/glue/elastic_search/errata.rb index ab88e8576a0..9616a714e5c 100644 --- a/app/models/glue/elastic_search/errata.rb +++ b/app/models/glue/elastic_search/errata.rb @@ -98,7 +98,7 @@ def self.repos_for_filter(filter) end return products.map {|p| p.repos(env) }.flatten else - raise "Not enough arguments for finding repos" + fail "Not enough arguments for finding repos" end end diff --git a/app/models/glue/provider.rb b/app/models/glue/provider.rb index f53b7164eca..b3acceffd1e 100644 --- a/app/models/glue/provider.rb +++ b/app/models/glue/provider.rb @@ -191,7 +191,7 @@ def owner_upstream_update(upstream, options) if !upstream['idCert'] || !upstream['idCert']['cert'] || !upstream['idCert']['key'] Rails.logger.error "Upstream identity certificate not available" - raise _("Upstream identity certificate not available") + fail _("Upstream identity certificate not available") end # Default to Red Hat @@ -214,7 +214,7 @@ def owner_upstream_export(upstream, zip_file_path, options) if !upstream['idCert'] || !upstream['idCert']['cert'] || !upstream['idCert']['key'] Rails.logger.error "Upstream identity certificate not available" - raise _("Upstream identity certificate not available") + fail _("Upstream identity certificate not available") end # Default to Red Hat @@ -268,7 +268,7 @@ def failed_products_status # rubocop:disable MethodLength def queue_import_manifest(options) options = options.with_indifferent_access - raise "zip_file_path or upstream must be specified" if options[:zip_file_path].nil? && options[:upstream].nil? + fail "zip_file_path or upstream must be specified" if options[:zip_file_path].nil? && options[:upstream].nil? #if a manifest has already been imported, we need to update the products manifest_update = self.products.any? diff --git a/app/models/glue/pulp/repo.rb b/app/models/glue/pulp/repo.rb index a313f31f3b0..710d1dbd909 100644 --- a/app/models/glue/pulp/repo.rb +++ b/app/models/glue/pulp/repo.rb @@ -143,7 +143,7 @@ def generate_importer when Repository::PUPPET_TYPE Runcible::Models::PuppetImporter.new(:feed => self.feed) else - raise _("Unexpected repo type %s") % self.content_type + fail _("Unexpected repo type %s") % self.content_type end end @@ -167,7 +167,7 @@ def generate_distributors {:id => self.pulp_id, :auto_publish => true}) [puppet_install_dist, nodes_distributor] else - raise _("Unexpected repo type %s") % self.content_type + fail _("Unexpected repo type %s") % self.content_type end end @@ -193,7 +193,7 @@ def importer_type when Repository::PUPPET_TYPE Runcible::Models::PuppetImporter::ID else - raise _("Unexpected repo type %s") % self.content_type + fail _("Unexpected repo type %s") % self.content_type end end @@ -503,7 +503,7 @@ def clone_contents_by_filter(to_repo, content_type, filter_clauses, override_con Errata::CONTENT_TYPE => :errata, PuppetModule::CONTENT_TYPE => :puppet_module } - raise "Invalid content type #{content_type} sent. It needs to be one of #{content_classes.keys}"\ + fail "Invalid content type #{content_type} sent. It needs to be one of #{content_classes.keys}"\ unless content_classes[content_type] criteria = {} if content_type == Runcible::Extensions::Rpm.content_type @@ -681,8 +681,8 @@ def publish_clone_distributor(source_repo) dist = find_distributor(true) source_dist = source_repo.find_distributor - raise "Could not find #{self.content_type} clone distributor for #{self.pulp_id}" if dist.nil? - raise "Could not find #{self.content_type} distributor for #{source_repo.pulp_id}" if source_dist.nil? + fail "Could not find #{self.content_type} clone distributor for #{self.pulp_id}" if dist.nil? + fail "Could not find #{self.content_type} distributor for #{source_repo.pulp_id}" if source_dist.nil? Katello.pulp_server.extensions.repository.publish(self.pulp_id, dist['id'], :override_config => {:source_repo_id => source_repo.pulp_id, :source_distributor_id => source_dist['id']}) diff --git a/app/models/glue/pulp/repos.rb b/app/models/glue/pulp/repos.rb index 08fe71579d1..33ffee36c23 100644 --- a/app/models/glue/pulp/repos.rb +++ b/app/models/glue/pulp/repos.rb @@ -51,7 +51,7 @@ def self.prepopulate!(products, environment, repos = [], content_view = nil) if environment.library? content_view = environment.default_content_view else - raise "No content view specified for a Non library environment #{environment.inspect}" + fail "No content view specified for a Non library environment #{environment.inspect}" end end @@ -373,7 +373,7 @@ def check_for_repo_conflicts(repo_name, repo_label) :environment_id => self.library.id ).count > 0 if is_dupe - raise Errors::ConflictException.new(_("Label has already been taken")) + fail Errors::ConflictException.new(_("Label has already been taken")) end unless repo_label.blank? is_dupe = Repository.where(:label => repo_label, @@ -381,7 +381,7 @@ def check_for_repo_conflicts(repo_name, repo_label) :environment_id => self.library.id ).count > 0 if is_dupe - raise Errors::ConflictException.new(_("Label has already been taken")) + fail Errors::ConflictException.new(_("Label has already been taken")) end end end diff --git a/app/models/glue/pulp/user.rb b/app/models/glue/pulp/user.rb index 8f54a5c8a4e..8b1ce172a88 100644 --- a/app/models/glue/pulp/user.rb +++ b/app/models/glue/pulp/user.rb @@ -54,7 +54,7 @@ def set_pulp_user(args = {}) end rescue => e Rails.logger.error "Failed to create pulp user #{self.remote_id}: #{e}, #{e.backtrace.join("\n")}" - raise e + fail e end def set_super_user_role diff --git a/app/models/hypervisor.rb b/app/models/hypervisor.rb index 52157095536..e8168cd2d3c 100644 --- a/app/models/hypervisor.rb +++ b/app/models/hypervisor.rb @@ -19,7 +19,7 @@ class Hypervisor < System UNSUPPORTED_ACTIONS.each do |unsupported_action| define_method(unsupported_action) do - raise Errors::UnsupportedActionException.new(unsupported_action, self, _("Hypervisor does not support this action")) + fail Errors::UnsupportedActionException.new(unsupported_action, self, _("Hypervisor does not support this action")) end end end diff --git a/app/models/kt_environment.rb b/app/models/kt_environment.rb index 752000c9a50..aba3ab64b29 100644 --- a/app/models/kt_environment.rb +++ b/app/models/kt_environment.rb @@ -143,7 +143,7 @@ def path s = self.successor ret = [self] until s.nil? - raise "Environment path has duplicates!!. #{self}. Duplicate => #{ret}. Path => #{s}" if ret.include? s + fail "Environment path has duplicates!!. #{self}. Duplicate => #{ret}. Path => #{s}" if ret.include? s ret << s s = s.successor end diff --git a/app/models/organization.rb b/app/models/organization.rb index 9ed89eae030..e92b391ac1c 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -132,8 +132,8 @@ def validate_destroy(current_org) end def discover_repos(url, notify = false) - raise _("Repository Discovery already in progress") if self.repo_discovery_task && !self.repo_discovery_task.finished? - raise _("Discovery URL not set.") if url.blank? + fail _("Repository Discovery already in progress") if self.repo_discovery_task && !self.repo_discovery_task.finished? + fail _("Discovery URL not set.") if url.blank? task = self.async(:organization => self, :task_type => :repo_discovery).start_discovery_task(url, notify) task.parameters = {:url => url} self.task_statuses << task @@ -168,7 +168,7 @@ def self.check_informable_type!(informable_type, options = {}) options = defaults.merge(options) unless ALLOWED_DEFAULT_INFO_TYPES.include?(informable_type) - raise options[:error], options[:message] + fail options[:error], options[:message] end end diff --git a/app/models/organization_destroyer.rb b/app/models/organization_destroyer.rb index 0ecba126485..cacedcc1b25 100644 --- a/app/models/organization_destroyer.rb +++ b/app/models/organization_destroyer.rb @@ -26,7 +26,7 @@ def initialize(organization, options = { }) end def setup(organization) - raise NotImplementedError unless options[:async] + fail NotImplementedError unless options[:async] task = self.async.run organization.deletion_task_id = task.id diff --git a/app/models/permission.rb b/app/models/permission.rb index 7d551f1766e..31729ce40ea 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -167,7 +167,7 @@ def check_global def check_locked if self.role.locked? - raise ActiveRecord::ReadOnlyRecord, _("Cannot add/remove or change permissions related to a locked role.") + fail ActiveRecord::ReadOnlyRecord, _("Cannot add/remove or change permissions related to a locked role.") end end diff --git a/app/models/ping.rb b/app/models/ping.rb index b5740b8622c..e3085331033 100644 --- a/app/models/ping.rb +++ b/app/models/ping.rb @@ -92,7 +92,7 @@ def ping # katello jobs - TODO we should not spawn processes exception_watch(result[:status][:katello_jobs]) do - raise _("katello-jobs service not running") unless system("/sbin/service katello-jobs status") + fail _("katello-jobs service not running") unless system("/sbin/service katello-jobs status") end # set overall status result code @@ -132,7 +132,7 @@ def pulp_without_oauth http.verify_mode = OpenSSL::SSL::VERIFY_NONE end unless http.options(uri.path).content_length > 0 - raise _("Pulp not running") + fail _("Pulp not running") end end end diff --git a/app/models/product.rb b/app/models/product.rb index 5af7d4503eb..931b0bdd115 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -89,7 +89,7 @@ def initialize(attrs = nil, options = {}) def repos(env, include_disabled = false, content_view = nil, include_feedless = true) if content_view.nil? if !env.library? - raise "No content view specified for the repos call in a " + + fail "No content view specified for the repos call in a " + "Non library environment #{env.inspect}" else content_view = env.default_content_view diff --git a/app/models/promotion_changeset.rb b/app/models/promotion_changeset.rb index d5ed5ce6721..930a29485e2 100644 --- a/app/models/promotion_changeset.rb +++ b/app/models/promotion_changeset.rb @@ -26,7 +26,7 @@ def apply(options = { }) self.content_views.composite.each do |view| components = view.components_not_in_env(self.environment) - self.content_views unless components.blank? - raise _("Please add '%{component_content_views}' to the changeset '%{changeset}' "\ + fail _("Please add '%{component_content_views}' to the changeset '%{changeset}' "\ "if you wish to promote the composite view '%{composite_view}' with it.") % { :component_content_views => components.map(&:name).join(', '), :changeset => self.name, :composite_view => view.name} diff --git a/app/models/provider.rb b/app/models/provider.rb index 623aa3e6543..66ed1f55b8c 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -118,7 +118,7 @@ def serializable_hash(options = {}) # refreshes products' repositories from CDS. If new versions are released on # the CDN, this method will provide loading this new versions. def refresh_products - raise _("Products cannot be refreshed for custom provider.") unless self.redhat_provider? + fail _("Products cannot be refreshed for custom provider.") unless self.redhat_provider? self.products.engineering.each do |product| product.productContent.each do |pc| product.refresh_content(pc.content.id) if pc.katello_enabled? #only refresh PCs that are already enabled @@ -159,9 +159,9 @@ def manifest_task end def discover_repos(notify = false) - raise _("Cannot discover repos for the Red Hat Provider") if self.redhat_provider? - raise _("Repository Discovery already in progress") if self.discovery_task && !self.discovery_task.finished? - raise _("Discovery URL not set.") if self.discovery_url.blank? + fail _("Cannot discover repos for the Red Hat Provider") if self.redhat_provider? + fail _("Repository Discovery already in progress") if self.discovery_task && !self.discovery_task.finished? + fail _("Discovery URL not set.") if self.discovery_url.blank? self.discovered_repos = [] self.discovery_task = self.async(:organization => self.organization).start_discovery_task(notify) self.save! diff --git a/app/models/pulp_task_status.rb b/app/models/pulp_task_status.rb index aba5cdebe1d..5b81bb78819 100644 --- a/app/models/pulp_task_status.rb +++ b/app/models/pulp_task_status.rb @@ -99,7 +99,7 @@ def self.any_task_running(async_tasks) if !t.finished? return true elsif t.error? - raise RuntimeError, t.as_json + fail t.as_json end end return false diff --git a/app/models/repository.rb b/app/models/repository.rb index 2c2fd9e5f8e..45ae1b387e4 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -220,18 +220,18 @@ def clone_id(env, content_view) def create_clone(to_env, content_view = nil) content_view = to_env.default_content_view if content_view.nil? view_version = content_view.version(to_env) - raise _("View %{view} has not been promoted to %{env}") % + fail _("View %{view} has not been promoted to %{env}") % {:view => content_view.name, :env => to_env.name} if view_version.nil? library = self.library_instance ? self.library_instance : self if content_view.default? - raise _("Cannot clone repository from %{from_env} to %{to_env}. They are not sequential.") % + fail _("Cannot clone repository from %{from_env} to %{to_env}. They are not sequential.") % {:from_env => self.environment.name, :to_env => to_env.name} if to_env.prior != self.environment - raise _("Repository has already been promoted to %{to_env}") % + fail _("Repository has already been promoted to %{to_env}") % {:to_env => to_env} if self.is_cloned_in?(to_env) else - raise _("Repository has already been cloned to %{cv_name} in environment %{to_env}") % + fail _("Repository has already been cloned to %{cv_name} in environment %{to_env}") % {:to_env => to_env, :cv_name => content_view.name} if content_view.repos(to_env).where(:library_instance_id => library.id).count > 0 end diff --git a/app/models/resource_type.rb b/app/models/resource_type.rb index f0a9fb10259..7da12407bc9 100644 --- a/app/models/resource_type.rb +++ b/app/models/resource_type.rb @@ -92,7 +92,7 @@ def self.check(resource_type, verbs = []) end def self.check_type(resource_type) - raise ResourceTypeNotFound.new(resource_type, TYPES.keys) unless TYPES.key? resource_type + fail ResourceTypeNotFound.new(resource_type, TYPES.keys) unless TYPES.key? resource_type end if Katello.config.katello? diff --git a/app/models/role.rb b/app/models/role.rb index 54cfca42cb2..219d5e4c21b 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -42,7 +42,7 @@ def add_ldap_group(group_name) def remove_ldap_group(group_name) ldap_group = self.ldap_group_roles.where(:ldap_group => group_name).first - raise Errors::NotFound.new(_("LDAP group '%{group}' associated to role '%{role}' was not found.") % {:group => group_name, :role => self.name}) unless ldap_group + fail Errors::NotFound.new(_("LDAP group '%{group}' associated to role '%{role}' was not found.") % {:group => group_name, :role => self.name}) unless ldap_group ldap_group.destroy self.users.each { |user| user.set_ldap_roles } end @@ -113,7 +113,7 @@ def self.make_super_admin_role superadmin_role = Role.find_or_create_by_name( :name => ADMINISTRATOR, :description => 'Super administrator with all access.') - raise "Unable to create super-admin role: #{superadmin_role}" if superadmin_role.nil? || superadmin_role.errors.size > 0 + fail "Unable to create super-admin role: #{superadmin_role}" if superadmin_role.nil? || superadmin_role.errors.size > 0 #unlock role in case permission needs to be created superadmin_role.update_attributes(:locked => false) @@ -122,7 +122,7 @@ def self.make_super_admin_role :name => "super-admin-perm", :description => 'Super Admin permission', :role => superadmin_role, :all_types => true) - raise "Unable to create super-admin role permission: #{superadmin_role_perm}" if superadmin_role_perm.nil? || superadmin_role_perm.errors.size > 0 + fail "Unable to create super-admin role permission: #{superadmin_role_perm}" if superadmin_role_perm.nil? || superadmin_role_perm.errors.size > 0 superadmin_role.update_attributes(:locked => true) superadmin_role @@ -175,7 +175,7 @@ def super_admin_check(user) if superadmin? && users.length == 1 message = _("Cannot dissociate user '%{user}' from '%{role}' role. Need at least one user in the '%{role}' role.") % {:user => user.username, :role => name} errors[:base] << message - raise ActiveRecord::RecordInvalid, self + fail ActiveRecord::RecordInvalid, self end end end diff --git a/app/models/system_group.rb b/app/models/system_group.rb index 17a58c43dd9..46d36aa5e27 100644 --- a/app/models/system_group.rb +++ b/app/models/system_group.rb @@ -87,44 +87,44 @@ def remove_system(system) end def install_packages(packages) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.install_package(packages) save_job(pulp_job, :package_install, :packages, packages) end def uninstall_packages(packages) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.uninstall_package(packages) save_job(pulp_job, :package_remove, :packages, packages) end def update_packages(packages = nil) # if no packages are provided, a full system update will be performed (e.g ''yum update' equivalent) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.update_package(packages) save_job(pulp_job, :package_update, :packages, packages) end def install_package_groups(groups) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.install_package_group(groups) save_job(pulp_job, :package_group_install, :groups, groups) end def update_package_groups(groups) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.install_package_group(groups) save_job(pulp_job, :package_group_update, :groups, groups) end def uninstall_package_groups(groups) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.uninstall_package_group(groups) save_job(pulp_job, :package_group_remove, :groups, groups) end def install_errata(errata_ids) - raise Errors::SystemGroupEmptyException if self.systems.empty? + fail Errors::SystemGroupEmptyException if self.systems.empty? pulp_job = self.install_consumer_errata(errata_ids) save_job(pulp_job, :errata_install, :errata_ids, errata_ids) end @@ -203,13 +203,13 @@ def save_system_environments sys_envs = self.systems.collect{|s| s.environment_id}.uniq group_envs = @cached_environments.collect{|e| e.id} if (sys_envs - group_envs).length > 0 - raise _("Could not modify environments. System group membership does not match new environment association.") + fail _("Could not modify environments. System group membership does not match new environment association.") end #verify that keys match modified environments keys = self.environment_key_conflicts if !keys.empty? - raise _("Could not modify environments. One or more associated activation keys (%s) would become invalid.") % keys.collect{|k| k.name}.join(',') + fail _("Could not modify environments. One or more associated activation keys (%s) would become invalid.") % keys.collect{|k| k.name}.join(',') end end self.db_environments = self.environments diff --git a/app/models/tag.rb b/app/models/tag.rb index 0e5a1f204b6..83fef643180 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -18,7 +18,7 @@ def self.formatted(resource_type_name, tag_id) tags = model_klass.tags(tag_id) rescue [] return tags[0] if tags && !tags.empty? else - raise "Unrecognized model #{model_klass}" + fail "Unrecognized model #{model_klass}" end tag_id @@ -32,7 +32,7 @@ def self.tags_for(resource_type_name, organization_id) tag_list ||= [] return tag_list else - raise "Unrecognized model #{model_klass}" + fail "Unrecognized model #{model_klass}" end end diff --git a/app/models/user.rb b/app/models/user.rb index 2ce14d166c4..5604ffcefb7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,7 +150,7 @@ def self.create_ldap_user!(username) end def self.cp_oauth_header - raise Errors::UserNotSet, "unauthenticated to call a backend engine" if User.current.nil? + fail Errors::UserNotSet, "unauthenticated to call a backend engine" if User.current.nil? User.current.cp_oauth_header end @@ -425,7 +425,7 @@ def super_admin_check(role) if role.superadmin? && role.users.length == 1 message = _("Cannot dissociate user '%{username}' from '%{role}' role. Need at least one user in the '%{role}' role.") % {:username => username, :role => role.name} errors[:base] << message - raise ActiveRecord::RecordInvalid, self + fail ActiveRecord::RecordInvalid, self end end diff --git a/app/models/virtual_tag.rb b/app/models/virtual_tag.rb index 76e77a350b9..fd87b02098c 100644 --- a/app/models/virtual_tag.rb +++ b/app/models/virtual_tag.rb @@ -17,8 +17,8 @@ class VirtualTag attr_accessor :name, :display_name def initialize(name, display_name) - raise ArgumentError, "Name cannot be nil or empty" if name.nil? || name == '' - raise ArgumentError, "Display name cannot be nil or empty" if display_name.nil? || display_name == '' + fail ArgumentError, "Name cannot be nil or empty" if name.nil? || name == '' + fail ArgumentError, "Display name cannot be nil or empty" if display_name.nil? || display_name == '' self.name = name self.display_name = display_name end diff --git a/config/application.rb b/config/application.rb index 91ba98b3792..1824125553a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -51,7 +51,7 @@ # TODO: replace ENV['TRAVIS'] with configuration basic_groups + [:development, :test, (:debugging if ENV['TRAVIS'] != 'true')] else - raise "unknown environment #{Rails.env.to_sym}" + fail "unknown environment #{Rails.env.to_sym}" end.compact Bundler.require(*groups) end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index d5f2cde8e8a..750a53d059f 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -3,7 +3,7 @@ begin # Read token string from the file. token = IO.read('/etc/katello/secret_token') - fail RuntimeError, 'Size is too small' if token.length < 9 + fail 'Size is too small' if token.length < 9 Src::Application.config.secret_token = token.chomp rescue => e # If anything is wrong make sure the token is random. This is safe even when diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb index 7299c5557c6..c6901c4bcec 100644 --- a/config/initializers/warden.rb +++ b/config/initializers/warden.rb @@ -36,12 +36,12 @@ class Warden::SessionSerializer def serialize(user) - raise ArgumentError, "Cannot serialize invalid user object: #{user}" if !(user.is_a?(User) && user.id.is_a?(Integer)) + fail ArgumentError, "Cannot serialize invalid user object: #{user}" if !(user.is_a?(User) && user.id.is_a?(Integer)) user.id end def deserialize(id) - raise ArgumentError, "Cannot deserialize non-integer id: #{id}" unless id.is_a?(Integer) + fail ArgumentError, "Cannot deserialize non-integer id: #{id}" unless id.is_a?(Integer) User.find(id) rescue nil end end diff --git a/db/migrate/20130226133232_add_environment_default_id_to_content_view.rb b/db/migrate/20130226133232_add_environment_default_id_to_content_view.rb index 413995cbbd5..f920dffacab 100644 --- a/db/migrate/20130226133232_add_environment_default_id_to_content_view.rb +++ b/db/migrate/20130226133232_add_environment_default_id_to_content_view.rb @@ -8,7 +8,7 @@ def self.up cv.environment_default_id = env.id cv.save! end - raise "All environments not properly migrated" if KTEnvironment.count != ContentView.where("environment_default_id is not null").count + fail "All environments not properly migrated" if KTEnvironment.count != ContentView.where("environment_default_id is not null").count remove_column :environments, :default_content_view_id add_index :content_views, [:environment_default_id] diff --git a/db/seeds.rb b/db/seeds.rb index 2b9de99f478..6da9b6375e6 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -23,7 +23,7 @@ def format_errors(model = nil) # create read *everything* role and assign permissions to it reader_role = Role.make_readonly_role('Read Everything') -raise "Unable to create reader role: #{format_errors reader_role}" if reader_role.nil? || reader_role.errors.size > 0 +fail "Unable to create reader role: #{format_errors reader_role}" if reader_role.nil? || reader_role.errors.size > 0 reader_role.update_attributes(:locked => true) # create the super admin if none exist - it must be created before any statement in the seed.rb script @@ -38,7 +38,7 @@ def format_errors(model = nil) User.current = user_admin user_admin.save! end -raise "Unable to create admin user: #{format_errors user_admin}" if user_admin.nil? || user_admin.errors.size > 0 +fail "Unable to create admin user: #{format_errors user_admin}" if user_admin.nil? || user_admin.errors.size > 0 unless hidden_user = User.hidden.first hidden_user = User.new( @@ -49,14 +49,14 @@ def format_errors(model = nil) :hidden => true) hidden_user.save! end -raise "Unable to create hidden user: #{format_errors hidden_user}" if hidden_user.nil? || hidden_user.errors.size > 0 +fail "Unable to create hidden user: #{format_errors hidden_user}" if hidden_user.nil? || hidden_user.errors.size > 0 first_org_desc = first_org_name + " Organization" first_org_label = first_org_name.gsub(' ', '_') # create the default org = "admin" if none exist first_org = Organization.find_or_create_by_name(:name => first_org_name, :label => first_org_label, :description => first_org_desc, :label => first_org_label) -raise "Unable to create first org: #{format_errors first_org}" if first_org && first_org.errors.size > 0 -raise "Are you sure you cleared candlepin?! Unable to create first org!" if first_org.environments.nil? +fail "Unable to create first org: #{format_errors first_org}" if first_org && first_org.errors.size > 0 +fail "Are you sure you cleared candlepin?! Unable to create first org!" if first_org.environments.nil? #create a provider if Provider.count == 0 diff --git a/engines/fort/app/controllers/api/v1/nodes_controller.rb b/engines/fort/app/controllers/api/v1/nodes_controller.rb index 14c4fd8a6d4..8dfcd6d9ef0 100644 --- a/engines/fort/app/controllers/api/v1/nodes_controller.rb +++ b/engines/fort/app/controllers/api/v1/nodes_controller.rb @@ -66,7 +66,7 @@ def show_by_uuid system = System.find_by_uuid!(params[:uuid]) @node = Node.find_by_system_id(system.id) unless @node - raise HttpErrors::NotFound, _("System %s is not a registered node") % params[:uuid] + fail HttpErrors::NotFound, _("System %s is not a registered node") % params[:uuid] end respond_for_show end diff --git a/engines/fort/app/models/content_node_capability.rb b/engines/fort/app/models/content_node_capability.rb index 3669e8f7c69..7645bb859bb 100644 --- a/engines/fort/app/models/content_node_capability.rb +++ b/engines/fort/app/models/content_node_capability.rb @@ -17,7 +17,7 @@ class ContentNodeCapability < NodeCapability after_save :enable_pulp_node def validate_configuration - raise _("Oauth credentials cannot be blank") if self.configuration['oauth'].blank? + fail _("Oauth credentials cannot be blank") if self.configuration['oauth'].blank? end def enable_pulp_node diff --git a/engines/fort/app/models/node_capability.rb b/engines/fort/app/models/node_capability.rb index 3b5f3ef4023..e05b1d081ea 100644 --- a/engines/fort/app/models/node_capability.rb +++ b/engines/fort/app/models/node_capability.rb @@ -28,15 +28,15 @@ def self.class_for(type) end def update_environments - raise "update_environments not implemented" + fail "update_environments not implemented" end def sync(options = {}) - raise "Sync Not implemented" + fail "Sync Not implemented" end def validate_configuration - raise "Empty capability not supported" + fail "Empty capability not supported" end end diff --git a/lib/katello/configuration/loader.rb b/lib/katello/configuration/loader.rb index 24ece330927..61e36dcddd0 100644 --- a/lib/katello/configuration/loader.rb +++ b/lib/katello/configuration/loader.rb @@ -33,9 +33,9 @@ class Loader # @option options [Proc] :load_yml_post_process called on each configuration loaded from yaml file # e.g. to decrypt db password def initialize(options = {}) - @config_file_paths = options[:config_file_paths] || raise(ArgumentError) - @default_config_file_path = options[:default_config_file_path] || raise(ArgumentError) - @validation = options[:validation] || raise(ArgumentError) + @config_file_paths = options[:config_file_paths] || fail(ArgumentError) + @default_config_file_path = options[:default_config_file_path] || fail(ArgumentError) + @validation = options[:validation] || fail(ArgumentError) @config_post_process = options[:config_post_process] @load_yml_post_process = options[:load_yml_post_process] end @@ -98,7 +98,7 @@ def load_yml_file(file_path) when nil, false, '' {} else - raise "malformed yml file '#{file_path}'" + fail "malformed yml file '#{file_path}'" end Node.new(hash_parsed_yml).tap do |config| @@ -121,7 +121,7 @@ def validate(config, environment) def config_file_path @config_file_path ||= config_file_paths.find { |path| File.exist? path } - raise "no config file found, candidates: #{config_file_paths.join ' '}" unless @config_file_path + fail "no config file found, candidates: #{config_file_paths.join ' '}" unless @config_file_path @config_file_path end end diff --git a/lib/katello/configuration/node.rb b/lib/katello/configuration/node.rb index 96ee36cfe34..3ed3610dc76 100644 --- a/lib/katello/configuration/node.rb +++ b/lib/katello/configuration/node.rb @@ -44,7 +44,7 @@ def [](key) if key? key @data[key].is_a?(Proc) ? @data[key].call : @data[key] else - raise NoKey, key + fail NoKey, key end end @@ -63,7 +63,7 @@ def key?(key) # node.present? :key1, :key2 def present?(*keys) key, rest = keys.first, keys[1..-1] - raise ArgumentError, 'supply at least one key' unless key + fail ArgumentError, 'supply at least one key' unless key key?(key) && self[key] && if rest.empty? true elsif self[key].is_a?(Node) @@ -133,7 +133,7 @@ def convert(obj) # converts Hash by symbolizing keys and allowing only symbols as keys def convert_hash(hash) - raise ArgumentError, "#{hash.inspect} is not a Hash" unless hash.is_a?(Hash) + fail ArgumentError, "#{hash.inspect} is not a Hash" unless hash.is_a?(Hash) hash.keys.each do |key| hash[key.to_s] = convert hash.delete(key) diff --git a/lib/katello/configuration/validator.rb b/lib/katello/configuration/validator.rb index 3c86b672766..6d7811f6f0b 100644 --- a/lib/katello/configuration/validator.rb +++ b/lib/katello/configuration/validator.rb @@ -48,14 +48,14 @@ def is_boolean(key) def is_type(key, *types) unless types.any? { |type| type === config[key] } - raise error_format(key.to_sym, "has to be one of #{types.inspect} types") + fail error_format(key.to_sym, "has to be one of #{types.inspect} types") end end def has_values(key, values, options = {}) values << nil if options[:allow_nil] return true if values.include?(config[key]) - raise ArgumentError, error_format(key, "should be one of #{values.inspect}, but was #{config[key].inspect}") + fail ArgumentError, error_format(key, "should be one of #{values.inspect}, but was #{config[key].inspect}") end def has_keys(*keys) @@ -64,7 +64,7 @@ def has_keys(*keys) def has_key(key) unless config.key? key.to_sym - raise error_format(key.to_sym, 'is required') + fail error_format(key.to_sym, 'is required') end end @@ -78,7 +78,7 @@ def error_format(key, message) def is_not_empty(key) if config[key].nil? || config[key].empty? - raise error_format(key.to_sym, "must not be empty") + fail error_format(key.to_sym, "must not be empty") end end end diff --git a/lib/katello/logging.rb b/lib/katello/logging.rb index ca50d137f00..f2398988997 100644 --- a/lib/katello/logging.rb +++ b/lib/katello/logging.rb @@ -16,7 +16,7 @@ class LoggingImpl private_class_method :new def configure(options = {}) - raise 'logging can be configured only once' if @configured + fail 'logging can be configured only once' if @configured @configured = true configure_color_scheme @@ -155,7 +155,7 @@ def build_root_appender(options) when 'file' build_file_appender(name, options) else - raise 'unsupported logger type, please choose syslog or file' + fail 'unsupported logger type, please choose syslog or file' end end diff --git a/lib/monkeys/yard_svg_fix.rb b/lib/monkeys/yard_svg_fix.rb index 1ec30572a95..b60c1403489 100644 --- a/lib/monkeys/yard_svg_fix.rb +++ b/lib/monkeys/yard_svg_fix.rb @@ -7,7 +7,7 @@ class DisplayFileCommand < LibraryCommand def run path = library.source_path filename = File.cleanpath(File.join(library.source_path, path)) - raise NotFoundError if !File.file?(filename) + fail NotFoundError if !File.file?(filename) if filename =~ /\.(jpe?g|gif|png|bmp|svg)$/i headers['Content-Type'] = StaticFileCommand::DefaultMimeTypes[$1.downcase] || ("image/svg+xml" if $1.downcase == 'svg') || 'text/html' diff --git a/lib/string_to_bool.rb b/lib/string_to_bool.rb index c568e03dfbf..fa8b32fab97 100644 --- a/lib/string_to_bool.rb +++ b/lib/string_to_bool.rb @@ -14,6 +14,6 @@ class String def to_bool return true if self == true || self =~ (/(true|t|yes|y|1)$/i) return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i) - raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") + fail ArgumentError.new("invalid value for Boolean: \"#{self}\"") end end diff --git a/script/update_doc.rb b/script/update_doc.rb index 2bb0c35e0d3..25a7dcc20bb 100755 --- a/script/update_doc.rb +++ b/script/update_doc.rb @@ -15,7 +15,7 @@ def cmd(cmd) puts ">> #{cmd}" - raise "#{cmd} failed" unless system(cmd) + fail "#{cmd} failed" unless system(cmd) end unless File.exist? "#{root}/yardoc/.git"