From 0b841d63fd7e1c9f9d099bbd93cfa3a442630095 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Thu, 5 Mar 2020 14:44:23 -0800 Subject: [PATCH] Do not save exception in a variable if it isn't referenced Prior to this commit there were a couple locations where exceptions were saved to `_e` but weren't used in the handler except to re-raise the exception, which simply calling the `raise` keyword will do without a provided argument. This commit removes the unnecessary assignment of the exception to a variable and simply uses `raise` instead. --- lib/vmpooler/pool_manager.rb | 6 +++--- lib/vmpooler/providers/vsphere.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 6913f58..a37a6c4 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -330,11 +330,11 @@ module Vmpooler $logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds") $metrics.timing("clone.#{pool_name}", finish) - rescue StandardError => _e + rescue StandardError $redis.srem("vmpooler__pending__#{pool_name}", new_vmname) expiration_ttl = $config[:redis]['data_ttl'].to_i * 60 * 60 $redis.expire("vmpooler__vm__#{new_vmname}", expiration_ttl) - raise _e + raise ensure $redis.decr('vmpooler__tasks__clone') end @@ -1153,7 +1153,7 @@ module Vmpooler begin inventory = create_inventory(pool, provider, pool_check_response) - rescue StandardError => e + rescue StandardError return(pool_check_response) end diff --git a/lib/vmpooler/providers/vsphere.rb b/lib/vmpooler/providers/vsphere.rb index c8ef09a..2c9854a 100644 --- a/lib/vmpooler/providers/vsphere.rb +++ b/lib/vmpooler/providers/vsphere.rb @@ -173,9 +173,9 @@ module Vmpooler target[dc]['checking'] = true hosts_hash = find_least_used_hosts(cluster, datacenter, percentage) target[dc] = hosts_hash - rescue StandardError => _e + rescue StandardError target[dc] = {} - raise(_e) + raise ensure target[dc]['check_time_finished'] = Time.now end @@ -344,11 +344,11 @@ module Vmpooler begin vm_target_folder = find_vm_folder(pool_name, connection) vm_target_folder = create_folder(connection, target_folder_path, target_datacenter_name) if vm_target_folder.nil? && @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true) - rescue StandardError => _e + rescue StandardError if @config[:config].key?('create_folders') && (@config[:config]['create_folders'] == true) vm_target_folder = create_folder(connection, target_folder_path, target_datacenter_name) else - raise(_e) + raise end end @@ -986,9 +986,9 @@ module Vmpooler else logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}") end - rescue StandardError => _e + rescue StandardError logger.log('s', "[!] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}") - raise _e + raise end end end