Skip to content
Browse files

bubble up errors on connection failure and disconnect

  • Loading branch information...
1 parent f6f4706 commit 67b901558d2c08c9f2da99b223410c9d0756414a @outerim outerim committed Jun 10, 2009
Showing with 27 additions and 7 deletions.
  1. +1 −1 lib/pelvis/protocol.rb
  2. +7 −4 lib/pelvis/protocols/xmpp.rb
  3. +2 −1 run_herault
  4. +14 −0 spec/connection_spec.rb
  5. +3 −1 spec/helpers.rb
View
2 lib/pelvis/protocol.rb
@@ -21,7 +21,7 @@ def initialize(options, &block)
spawn
end
on_failed do |error|
- logger.error "Failed to connect: #{error}"
+ logger.error "Connection Error: #{error}"
end
end
attr_reader :options, :agent
View
11 lib/pelvis/protocols/xmpp.rb
@@ -6,6 +6,8 @@
module Pelvis
module Protocols
class XMPP < Protocol
+ class ConnectionError < RuntimeError; end
+
register :xmpp
def connect
@@ -50,19 +52,20 @@ def post_init
end
def unbind
- logger.warn "Got disconnected"
+ logger.warn "Got disconnected (unbind)"
+ failed(ConnectionError.new("got disconnected"))
end
def close
- logger.warn "Got disconnected"
+ logger.warn "Got disconnected (close)"
connect
end
def receive_data(stanza)
logger.debug "got a stanza for #{identity}:\n#{stanza.inspect}"
- if stanza.is_a?(Blather::BlatherError)
- failed stanza.message
+ if stanza.is_a?(Blather::BlatherError) || stanza.is_a?(Blather::SASLError)
+ failed stanza
return
end
View
3 run_herault
@@ -15,8 +15,9 @@ if ENV["DEBUGGER"]
end
EM.run do
- Pelvis.connect(:xmpp, :jid => "herault@localhost/agent", :password => "testing", :advertise => false) do |agent|
+ c = Pelvis.connect(:xmpp, :jid => "herault@localhost/agent", :password => "testing", :advertise => false) do |agent|
agent.add_actor Herault
agent.on_advertised { puts "herault is ready" }
end
+ c.on_failed { EM.stop }
end
View
14 spec/connection_spec.rb
@@ -0,0 +1,14 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+if ENV["PROTOCOL"] == 'xmpp'
+ describe "An xmpp connection" do
+ it "should fail if credentials are wrong" do
+ err = []
+ EM.run {
+ p = Pelvis.connect(:xmpp, :jid => 'bla@localhost/agent', :password => 'foo') { }
+ p.on_failed { |e| err << e; EM.stop }
+ }
+ err.first.should be_a_kind_of(Blather::SASLError)
+ end
+ end
+end
View
4 spec/helpers.rb
@@ -57,7 +57,9 @@ def agent_connect(agents, &block)
end
end
connection.on_failed do |error|
- raise "Error with #{connection.inspect}: #{error.inspect}"
+ unless error.kind_of?(Pelvis::Protocols::XMPP::ConnectionError)
+ raise "Error with #{connection.inspect}: #{error.inspect}"
+ end
end
end

0 comments on commit 67b9015

Please sign in to comment.
Something went wrong with that request. Please try again.