Skip to content

Commit

Permalink
Parse last_modified time only if it is valid
Browse files Browse the repository at this point in the history
```
options = { max_keys: 1 }
directories.get(@key, options)
```

We are getting the following stack trace for the above code on Azure Blobstore (as the response does not return "last_modified" on directory entries)


```
Caused by TypeError: no implicit conversion of nil into String
from /var/vcap/data/packages/ruby-2.5.5-r0.10.0/0dfbbae801575a6b5c084eec5c0bfb4826a6e4be/lib/ruby/2.5.0/time.rb:367:in `_parse'



[13] pry(VCAP::CloudController)> VCAP::CloudController::ResourcePool.new(Config.config).blobstore.exists?('asdf')
/var/vcap/data/packages/ruby-2.5.5-r0.10.0/0dfbbae801575a6b5c084eec5c0bfb4826a6e4be/lib/ruby/2.5.0/time.rb:367:in `_parse'
/var/vcap/data/packages/ruby-2.5.5-r0.10.0/0dfbbae801575a6b5c084eec5c0bfb4826a6e4be/lib/ruby/2.5.0/time.rb:367:in `parse'
/var/vcap/data/packages/cloud_controller_ng/213aa19eb0f9e335047b2a81dc299e4f15ab6f30/cloud_controller_ng/vendor/cache/fog-azure-rm-baaf3f4d684f/lib/fog/azurerm/utilities/general.rb:157:in `parse_storage_object'
/var/vcap/data/packages/cloud_controller_ng/213aa19eb0f9e335047b2a81dc299e4f15ab6f30/cloud_controller_ng/vendor/cache/fog-azure-rm-baaf3f4d684f/lib/fog/azurerm/models/storage/directories.rb:55:in `block in get'
/var/vcap/data/packages/cloud_controller_ng/213aa19eb0f9e335047b2a81dc299e4f15ab6f30/cloud_controller_ng/vendor/cache/fog-azure-rm-baaf3f4d684f/lib/fog/azurerm/models/storage/directories.rb:54:in `each'
/var/vcap/data/packages/cloud_controller_ng/213aa19eb0f9e335047b2a81dc299e4f15ab6f30/cloud_controller_ng/vendor/cache/fog-azure-rm-baaf3f4d684f/lib/fog/azurerm/models/storage/directories.rb:54:in `get'
/var/vcap/data/packages/cloud_controller_ng/213aa19eb0f9e335047b2a81dc299e4f15ab6f30/cloud_controller_ng/lib/cloud_controller/blobstore/fog/directory.rb:16:in `get'
```

Here's the XML response:
```
<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://leia.blob.core.windows.net/" ContainerName="resources"><MaxResults>1</MaxResults><Delimiter>/</Delimiter><Blobs><BlobPrefix><Name>app_bits_cache/</Name></BlobPrefix></Blobs><NextMarker /></EnumerationResults>
``` 

You can notice that there is no "last-modified" field.

I am not familiar with Ruby, hope this is the right way to fix this bug :-)
  • Loading branch information
krishnasrinivas authored Feb 25, 2020
1 parent ce715f6 commit 4e44131
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fog/azurerm/utilities/general.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def parse_storage_object(object)
end
end

data['last_modified'] = Time.parse(data['last_modified'])
data['last_modified'] = Time.parse(data['last_modified']) unless data['last_modified'].empty?
data['etag'].delete!('"')
data
end
Expand Down

0 comments on commit 4e44131

Please sign in to comment.