Skip to content

Commit

Permalink
refactor: prefer to always use raise (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Jun 16, 2023
1 parent 4ad5c44 commit 550b71b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ Metrics/MethodLength:
Naming/VariableNumber:
Enabled: false

# We prefer that you use `fail` unless you're explicitly re-raising an exception.
# Just always use `raise` and stop thinking about it.
Style/SignalException:
EnforcedStyle: semantic
EnforcedStyle: only_raise

# We think that:
# hash = {
Expand Down
2 changes: 1 addition & 1 deletion ci/bin/build-and-test
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ puts <<~EO_CONFIG_SUMMARY
EO_CONFIG_SUMMARY
puts "=" * 80

fail "Missing config YML file" unless File.exist?(config_path) & File.file?(config_path)
raise "Missing config YML file" unless File.exist?(config_path) & File.file?(config_path)

puts "Installing latest rails gem"
system "gem install rails --no-document"
Expand Down
8 changes: 4 additions & 4 deletions template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ def assert_valid_options
next unless options.key?(key)

actual = options[key]
fail Rails::Generators::Error, "Unsupported option: #{key}=#{actual}" unless actual == expected
raise Rails::Generators::Error, "Unsupported option: #{key}=#{actual}" unless actual == expected
end
end

def assert_postgresql
return if /^\s*gem ['"]pg['"]/.match?(File.read("Gemfile"))

fail Rails::Generators::Error,
"This template requires PostgreSQL, " \
"but the pg gem isn't present in your Gemfile."
raise Rails::Generators::Error,
"This template requires PostgreSQL, " \
"but the pg gem isn't present in your Gemfile."
end

def any_local_git_commits?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActiveStorage::BaseController < ActionController::Base # rubocop:disable R
# removed. If not then code should be added to only serve files appropriately.
# https://edgeguides.rubyonrails.org/active_storage_overview.html#proxy-mode
def authenticated?
fail StandardError, "No authentication is configured for ActiveStorage"
raise StandardError, "No authentication is configured for ActiveStorage"
end
end
# :nocov:
4 changes: 2 additions & 2 deletions variants/backend-base/config/initializers/check_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# RAILS_SECRET_KEY_BASE should be set to something other than its value in example.env

if Rails.env.production? && Rails.root.join("example.env").read.include?(ENV.fetch("RAILS_SECRET_KEY_BASE"))
fail "RAILS_SECRET_KEY_BASE is unchanged from example.env. " \
"Generate a new one with `bundle exec rails secret`"
raise "RAILS_SECRET_KEY_BASE is unchanged from example.env. " \
"Generate a new one with `bundle exec rails secret`"
end
4 changes: 2 additions & 2 deletions variants/backend-base/rubocop.yml.tt
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ Rails/SkipsModelValidations:
Naming/VariableNumber:
Enabled: false

# We prefer that you use `fail` unless you're explicitly re-raising an exception.
# Just always use `raise` and stop thinking about it.
Style/SignalException:
EnforcedStyle: semantic
EnforcedStyle: only_raise

# We think that:
# hash = {
Expand Down

0 comments on commit 550b71b

Please sign in to comment.