From d9ef244cda41959ad7ace1feaa18eaf0daf7f9eb Mon Sep 17 00:00:00 2001 From: Brian Chong Date: Wed, 12 Jul 2017 22:54:38 -0700 Subject: [PATCH] [Issue #54] Fix NilClass evaluation Occasionally, the results of either `check_job_status` or `check_batch_status` return nil. This commit adds conditions to protect against evaluating a NilClass. Error: undefined method `[]' for nil:NilClass (NoMethodError) --- lib/salesforce_bulk_api/job.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/salesforce_bulk_api/job.rb b/lib/salesforce_bulk_api/job.rb index 2b637c7..c24ffa6 100644 --- a/lib/salesforce_bulk_api/job.rb +++ b/lib/salesforce_bulk_api/job.rb @@ -169,12 +169,13 @@ def get_job_result(return_result, timeout) state = [] Timeout::timeout(timeout, SalesforceBulkApi::JobTimeout) do while true - if self.check_job_status['state'][0] == 'Closed' + job_status = self.check_job_status + if job_status && job_status['state'] && job_status['state'][0] == 'Closed' batch_statuses = {} batches_ready = @batch_ids.all? do |batch_id| batch_state = batch_statuses[batch_id] = self.check_batch_status(batch_id) - batch_state['state'][0] != "Queued" && batch_state['state'][0] != "InProgress" + batch_state && batch_state['state'] && batch_state['state'][0] && !['Queued', 'InProgress'].include?(batch_state['state'][0]) end if batches_ready