Skip to content

Commit

Permalink
fix: use correct Ruby exceptions:
Browse files Browse the repository at this point in the history
- StandardError for most exceptions
- Unleash::Strategy::NotImplemented should extend RuntimeError
  • Loading branch information
rarruda committed Nov 21, 2019
1 parent bc3d3a1 commit 7a22580
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/unleash/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def register
# Send the request, if possible
begin
response = http_send_request(info.to_json)
rescue Exception => e
rescue StandardError => e
Unleash.logger.error "unable to register client with unleash server due to exception #{e.class}:'#{e}'."
Unleash.logger.error "stacktrace: #{e.backtrace}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/unleash/scheduled_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_blk(blk)

yield(*blk)
self.retry_count = 0
rescue Exception => e
rescue StandardError => e
self.retry_count += 1
Unleash.logger.error "thread #{name} threw exception #{e.class} " \
" (#{self.retry_count}/#{self.max_exceptions}): '#{e}'"
Expand Down
2 changes: 1 addition & 1 deletion lib/unleash/strategy/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Unleash
module Strategy
class NotImplemented < Exception
class NotImplemented < RuntimeError
end

class Base
Expand Down
6 changes: 3 additions & 3 deletions lib/unleash/toggle_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize
# start by fetching synchronously, and failing back to reading the backup file.
begin
fetch
rescue Exception => e
rescue StandardError => e
Unleash.logger.warn "ToggleFetcher was unable to fetch from the network, attempting to read from backup file."
Unleash.logger.debug "Exception Caught: #{e}"
read!
Expand Down Expand Up @@ -73,7 +73,7 @@ def save!
file.write(self.toggle_cache.to_json)
File.rename(backup_file_tmp, backup_file)
end
rescue Exception => e
rescue StandardError => e
# This is not really the end of the world. Swallowing the exception.
Unleash.logger.error "Unable to save backup file. Exception thrown #{e.class}:'#{e}'"
Unleash.logger.error "stacktrace: #{e.backtrace}"
Expand Down Expand Up @@ -139,7 +139,7 @@ def read!
Unleash.logger.error "Unable to read the backup_file: #{e}"
rescue JSON::ParserError => e
Unleash.logger.error "Unable to parse JSON from existing backup_file: #{e}"
rescue Exception => e
rescue StandardError => e
Unleash.logger.error "Unable to extract valid data from backup_file. Exception thrown: #{e}"
ensure
file&.close
Expand Down

0 comments on commit 7a22580

Please sign in to comment.