Are Errors getting swallowed?

2 views
Skip to first unread message

mwlang

unread,
Nov 5, 2009, 3:44:25 PM11/5/09
to beanstalk-talk
I can't seem to catch errors and deal with them and I am also not sure
how to actually test that I have valid connections to a beanstalkd
service.

when I don't have a beanstalkd instance running locally, this code:

require 'beanstalk-client'
begin
BEANSTALK_QUEUE = Beanstalk::Pool.new(['0.0.0.0:11300'])
puts "#{'!' * 10} #{BEANSTALK_QUEUE.stats}"
rescue
puts "you caught an error"
end

Produces the following output:

Errno::ECONNREFUSED: Connection refused - connect(2)
Errno::ECONNREFUSED: Connection refused - connect(2)

How can I get at those reported errors and do something about them?

Keith Rarick

unread,
Nov 9, 2009, 3:25:27 AM11/9/09
to beansta...@googlegroups.com
On Thu, Nov 5, 2009 at 12:44 PM, mwlang <mwl...@cybrains.net> wrote:
> How can I get at those reported errors and do something about them?

In short, yes, they are getting swallowed. In the beanstalk client
gem, search for "rescue Exception" in
lib/beanstalk-client/connection.rb. There is a reason for catching
exceptions like that -- if you have several beanstalkds running, and
one is down, you (might) still want to connect and use the rest so
that service isn't interrupted. But this is a ham-fisted way to
accomplish that goal, and it causes other problems, such as the one
you encountered.

If you want to connect to just one beanstalkd instance, use
Beanstalk::Connection.new('0.0.0.0:11300') instead. That will give you
the errors as you would expect.

However, I am not very happy with the original ruby client. This isn't
its only flaw. I recommend checking out http://github.com/dj2/em-jack
instead. It is under more recent active development and it has a
better fundamental architecture (using EventMachine).

kr

Reply all
Reply to author
Forward
0 new messages