From 7a22580fcb445a219641fac944dbbe07ac6e1734 Mon Sep 17 00:00:00 2001 From: Renato Arruda Date: Tue, 29 Oct 2019 23:42:17 +0100 Subject: [PATCH] fix: use correct Ruby exceptions: - StandardError for most exceptions - Unleash::Strategy::NotImplemented should extend RuntimeError --- lib/unleash/client.rb | 2 +- lib/unleash/scheduled_executor.rb | 2 +- lib/unleash/strategy/base.rb | 2 +- lib/unleash/toggle_fetcher.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/unleash/client.rb b/lib/unleash/client.rb index a67d605b..00c9ea22 100644 --- a/lib/unleash/client.rb +++ b/lib/unleash/client.rb @@ -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 diff --git a/lib/unleash/scheduled_executor.rb b/lib/unleash/scheduled_executor.rb index f870f4f1..acf98ef1 100755 --- a/lib/unleash/scheduled_executor.rb +++ b/lib/unleash/scheduled_executor.rb @@ -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}'" diff --git a/lib/unleash/strategy/base.rb b/lib/unleash/strategy/base.rb index 87507ebb..3e3a0f07 100644 --- a/lib/unleash/strategy/base.rb +++ b/lib/unleash/strategy/base.rb @@ -1,6 +1,6 @@ module Unleash module Strategy - class NotImplemented < Exception + class NotImplemented < RuntimeError end class Base diff --git a/lib/unleash/toggle_fetcher.rb b/lib/unleash/toggle_fetcher.rb index a11a7ba3..3d2fb68d 100755 --- a/lib/unleash/toggle_fetcher.rb +++ b/lib/unleash/toggle_fetcher.rb @@ -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! @@ -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}" @@ -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