qoobaa / s3

Library for accessing S3 objects and buckets, supports EU and US buckets
MIT License
258 stars 112 forks source link

undefined method `to_hash' for nil:NilClass #91

Closed Dagnan closed 9 years ago

Dagnan commented 10 years ago

Hi.

When I do a simple object.build(my_key) and object.retrieve I get:

undefined method `to_hash' for nil:NilClass
    from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/s3-0.3.21/lib/s3/object.rb:249:in `parse_headers'
    from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/s3-0.3.21/lib/s3/object.rb:190:in `object_headers'
    from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/s3-0.3.21/lib/s3/object.rb:61:in `retrieve'
    from /opt/boxen/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/s3-0.3.21/lib/s3/objects_extension.rb:12:in `find_first'

Seems simple but not sure if it's a bug or me using the gem wrong.

qoobaa commented 10 years ago

It's going to be difficult to debug with the info you've provided. I'm not sure if it's a bug.

Mehonoshin commented 9 years ago

Hi guys, I faced the same issue. Created a new bucket via CyberDuck app, the file is present in the bucket. When I try to fetch it with s3 gem, it returns this error.

UPD: it seems to be some issue with S3 service, the error disappeared suddenly, without any fix. Looks like S3 returns empty response for request to this bucket.

arthurnn commented 9 years ago

This should be fixed in master, please try again, and let me know if it doesnt work. thanks

Avemark commented 9 years ago

Getting the exact same error.

created a bucket, added a single file.

bucket.objects.first.content  => actual file content
bucket.objects.first.key => actual file key
bucket.objects.first.request_acl => {"my s3 user"=>"FULL_CONTROL", "Everyone"=>"READ"}
bucket.objects.first.retrieve => NoMethodError: undefined method `to_hash' for nil:NilClass

precisely according to Dagnan's stacktrace above. The object_request for headers returns nil. (I guess, boiling down to the Connection.request method, and possibly an empty response from s3)

Avemark commented 9 years ago

It's indeed fixed in master. It'd be nice to see this change propagated to rubygems.

arthurnn commented 9 years ago

@qoobaa can you add me to rubygems so I can cut a new gem. thanks

qoobaa commented 9 years ago

@arthurnn done.

arthurnn commented 9 years ago

new version released https://rubygems.org/gems/s3/versions/0.3.22

RdNetwork commented 7 years ago

I am facing the same problem.

I have a working S3 bucket with files, and the bucket.objects method manages to correctly list my files, and get their contents, but is unable to retrieve them.

Example of output from the Rails console: 2.3.0 :009 > bucket => #<S3::Bucket:kyouko> 2.3.0 :010 > bucket.objects[125] => #<S3::Object:/kyouko/anime/147799.jpg> 2.3.0 :011 > bucket.objects[125].retrieve NoMethodError: undefined method 'to_hash' for nil:NilClass Did you mean? to_h from /home/rd/.rvm/gems/ruby-2.3.0/gems/s3-0.3.24/lib/s3/object.rb:245:in 'parse_headers' from /home/rd/.rvm/gems/ruby-2.3.0/gems/s3-0.3.24/lib/s3/object.rb:190:in 'object_headers' from /home/rd/.rvm/gems/ruby-2.3.0/gems/s3-0.3.24/lib/s3/object.rb:61:in 'retrieve'

Using the 'find' method also causes this problem, since it uses the 'retrieve' method. Same for 'exists?' which is actually the method I need to use in the first place. I am using v0.3.24. I thought this was fixed? Or is it another problem?

cavebring commented 7 years ago

+1 on this issue