Hpricot – [BUG] Bus Error – Solution / Workaround


You’re using Hpricot to parse web content, but it’s throwing an error like this that completely kills the process (probably crashing your app, or your background task, as the case may be):

/usr/local/lib/ruby/gems/1.8/gems/hpricot-0.8.2/lib/hpricot/parse.rb:33: [BUG] Bus Error
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin8.11.1]
Abort trap

This resource suggests that the problem is that the content retrieved is precisely 16384 bytes long, however, that was not the problem in my case.

My problem is replicated in this gist. Examination of the URL it was trying to retrieve using curl with -i indicated that this was returning a 302 redirect:

HTTP/1.1 302 Found
Date: Thu, 12 Nov 2009 14:50:53 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-UA-Compatible: IE=EmulateIE7
Location: /
Set-Cookie: ASP.NET_SessionId=p2s0dljru11tiwer3e01jfq2; path=/; HttpOnly
Set-Cookie: Forum2backURL=/tm.aspx?m=1859288#1859354; path=/
Set-Cookie: Forum2preURL=; path=/
Cache-Control: private
Expires: Wed, 11 Nov 2009 13:50:53 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 120

I am not sure why Ruby’s OpenURI open method was not capable of parsing / following this redirect. However, I determined that the file returned by open() had a size of zero bytes, and this was causing Hpricot to blow up.

My workaround is just to check the size of the file returned by open() and only try to parse it if it is greater than 0:

f = open(file_or_uri)
if f.size > 0
doc = Hpricot(f)
raise "Could not retrieve content due to zero-sized file, possibly due to site redirect."

25 Responses to “Hpricot – [BUG] Bus Error – Solution / Workaround”

  1. Hey – thanks for the post. Been googling this very error for over an hour now. There seems no way to adequately rescue the Bus Error Hpricot is throwing.


    Richard Luck

  2. Super-Duper site! I am loving it!! Will come back again. I am bookmarking your feeds also.

  3. You actually make it seem so easy along with your presentation but I find this matter to be actually something which I feel I’d never understand. It kind of feels too complicated and very broad for me. I’m having a look ahead to your next put up, I will attempt to get the hang of it!

  4. Outstandingly illuminating thanks, It is my opinion your current subscribers might just want a good deal more blog posts similar to this keep up the excellent content.

  5. Like EarthTechling, glad to check out them on below. Nino and Patricia know their things!

  6. Thanks for all of your labor on this website. My mom really loves working on research and it’s obvious why. All of us learn all regarding the compelling ways you convey vital thoughts through the website and as well strongly encourage contribution from other ones about this matter while our own child is being taught a lot. Take pleasure in the remaining portion of the new year. You are performing a wonderful job.

  7. Fantastic goods from you, man. I have understand your stuff previous to and you’re just too wonderful. I actually like what you have acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it wise. I cant wait to read far more from you. This is actually a terrific website.

  8. I appreciate you sharing this blog.Really looking forward to read more. Want more.

  9. There could be something incorrect with your links. You should have somebody check out it.

  10. The very next time I read a blog, Hopefully it doesn’t disappoint me as much as this particular one. After all, Yes, it was my choice to read through, but I truly thought you would probably have something useful to say. All I hear is a bunch of crying about something that you can fix if you weren’t too busy looking for attention.

  11. You are my aspiration, I have few blogs and occasionally run out from brand :). “The soul that is within me no man can degrade.” by Frederick Douglas.


    I like this site very much so much great info . “Our national flower is the concrete cloverleaf.” by Lewis Mumford.

  13. YESNANO:

    Some really fantastic articles on this site, appreciate it for contribution. “Be absolutely determined to enjoy what you do.” by Sarah Knowles Bolton.

  14. Note: the sources origin of this fund is from my father coffee and cocoa merchant industry and I’ve the deposit documents which my late father issued to me before his death which positive the fund is 100% threat cost-free.

  15. I blog often and I really appreciate your information. The article has truly peaked my interest. I’m going to take a note of your site and keep checking for new details about once a week. I opted in for your Feed as well.

  16. I am not assured where you’re getting your information, on the contrary vast matter. I wants to spend a number of epoch wisdom much additional or understanding added. Thanks for abundant in sequence I was looking used for this information for my mission.

  17. Have a look at this web-site at the moment:. Will not wait until the final minute to have your accounts funded, we are offering a Free entry to our 2013 $150k March Madness Bracket Contest for every deposit that comes in before Superbowl Sunday. Log into your account and enter the cashier to fund your account now! Should you forgot your password get in touch with us at February is Romantic Escape Month – Celebrate with 25% Financial savings!

  18. Always joyful to recite amazing articles.. Will be real in exchange representing added in support of sure! Thank you for sharing

  19. I’m no longer certain the place you are getting your info, however good topic. I needs to spend some time studying much more or working out more. Thanks for excellent info I was in search of this information for my mission.

  20. plastikowa biedronka piosenka

  21. Ade :: Hpricot – [BUG] Bus Error – Solution / Workaround

  22. boutiques nike paris…

    3 are generally temperature rature dom ta chambre/pi ce ne doit pas d passer 21oC….

  23. The things Every customer Need To Know Concerning bag Internet business

  24. Could an important women’s trench layer get on your behalf, as well as would it be proceeding in the form of surprise.

  25. compact country of panama and / or nicaragua, Elefntcsontpart. Horvtorszg. or a in some cases all the time at your days when the next thunderstis expectedm, the sunshine moments change as sunshine passes. Photochromic of add-ons assist in of which you renovation off visible and not having to stop put together with goes a great many technology. mostly these determination web site PPX protections give you something like 16 and in some cases 33 in every-any amount of money apparent pale signing always 13 may well 43 (unique Xtreme surprisingly affordable lamp service).
    [url=http://www.aabenraasynshal.dk/nikeairmax95.asp?p=4606]nike air max 1 german camo[/url]