Skip to content

Commit d9ef244

Browse files
author
Brian Chong
committed
[Issue yatish27#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)
1 parent 7423050 commit d9ef244

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/salesforce_bulk_api/job.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ def get_job_result(return_result, timeout)
169169
state = []
170170
Timeout::timeout(timeout, SalesforceBulkApi::JobTimeout) do
171171
while true
172-
if self.check_job_status['state'][0] == 'Closed'
172+
job_status = self.check_job_status
173+
if job_status && job_status['state'] && job_status['state'][0] == 'Closed'
173174
batch_statuses = {}
174175

175176
batches_ready = @batch_ids.all? do |batch_id|
176177
batch_state = batch_statuses[batch_id] = self.check_batch_status(batch_id)
177-
batch_state['state'][0] != "Queued" && batch_state['state'][0] != "InProgress"
178+
batch_state && batch_state['state'] && batch_state['state'][0] && !['Queued', 'InProgress'].include?(batch_state['state'][0])
178179
end
179180

180181
if batches_ready

0 commit comments

Comments
 (0)