Skip to content

Commit

Permalink
[Issue #54] Fix NilClass evaluation
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Brian Chong committed Jul 13, 2017
1 parent 7423050 commit d9ef244
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/salesforce_bulk_api/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9ef244

Please sign in to comment.