Aws::S3 Gem Bucket Does Not Exist Bug

June 10, 2010     

I just spent two hours debugging the most banal bug. It eventually reduced to the following wtf moment:

S3Object.store('a_key', 'some_content', 'a_bucket')
=> success
S3Object.find('a_key', 'a_bucket')
=> AWS::S3::NoSuchBucket: The specified bucket does not exist
    from .../vendor/gems/aws-s3-0.6.2/lib/aws/s3/error.rb:38:in `raise'
    from .../vendor/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:76:in `request'
    from .../vendor/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:92:in `get'
    from .../vendor/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:104:in `find'
    from .../vendor/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:172:in `find'
    from (irb):7

Okay, that makes no sense. It works in a vanilla irb. I smell a monkeypatch.

Sure enough, it turns out the Contacts gem and the AWS-S3 gem both define a Hash#to_query_string method. Here’s the kicker: both of those gems only call this method one time!

This is why monkeypatching should be considered harmful. I just wasted two hours of my life so someone could call options.to_query_string instead of to_query_string(options).