commit be27f17e729f333bb133c4e7138e25a2e9ea12f4
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Mon Nov 15 00:09:49 2010 +0100

    [evol] improve a bit how interface errors are transmitted

diff --git a/bin/mapmaker_client b/bin/mapmaker_client
index 43175f0..119851a 100755
--- a/bin/mapmaker_client
+++ b/bin/mapmaker_client
@@ -40,8 +40,20 @@ module CyborgHood
           if conv
             logger.info "Yo ! Conversation ready with MapMaker (#{conv.peer_name}) !"
             conv.thread("plop") do |conv_thread|
-              conv.protocol.send_request_call(conv_thread, "/api_version") do |reply|
-                pp reply
+              conv_thread.call("/api_version", 2) do |reply|
+                case reply[:status]
+                when :ok
+                  puts "Result:"
+                  pp reply[:result]
+                when :decline
+                  puts "Declined: #{reply[:reason]}"
+                when :error
+                  exception = reply[:exception]
+                  puts "EXCEPTION: [#{exception.severity} - #{exception.category}] #{exception.message}"
+pp exception.inspect
+                else
+                  puts "???"
+                end
               end
             end
           else
diff --git a/lib/cyborghood/cyborg/interface.rb b/lib/cyborghood/cyborg/interface.rb
index 900778d..a15a671 100644
--- a/lib/cyborghood/cyborg/interface.rb
+++ b/lib/cyborghood/cyborg/interface.rb
@@ -158,17 +158,17 @@ module CyborgHood
     # preliminary incoming message handling
     def call(session, cmd, data = nil)
       action = find_node_action(session, cmd)
-      raise "unknown node" if action.nil?
+      raise CyberError.new(:unrecoverable, 'api/cyborghood', "unknown node") if action.nil?
 
       data ||= []
-      raise "wrong format for arguments" unless data.is_a? Array
+      raise CyberError.new(:unrecoverable, 'api/cyborghood', "wrong format for arguments") unless data.is_a? Array
 
       begin
         action.call(*data)
       rescue
         logger.debug "node action error message: " + $!
         logger.debug "node action error backtrace: " + $!.backtrace.join("\n")
-        raise "method call failed: " + $!
+        raise CyberError.new(:unrecoverable, 'api/cyborghood', "method call failed: " + $!)
       end
     end
   end
diff --git a/lib/cyborghood/cyborg/protocol.rb b/lib/cyborghood/cyborg/protocol.rb
index 4f747cd..a571e3e 100644
--- a/lib/cyborghood/cyborg/protocol.rb
+++ b/lib/cyborghood/cyborg/protocol.rb
@@ -114,8 +114,18 @@ module CyborgHood
           result[:action_result] = @conversation.bot.interface.call(message.conv_thread.session,
                                                                     message.action_parameters[:node],
                                                                     message.action_parameters[:parameters])
+        rescue CyberError => e
+          result[:error] = {
+            :category  => e.category,
+            :severity  => e.severity,
+            :message   => e.message
+          }
         rescue
-          result[:error] = $!.to_s
+          result[:error] = {
+            :category  => 'unknown',
+            :severity  => :unrecoverable,
+            :message   => $!.to_s
+          }
         end
         result
       end
@@ -149,7 +159,9 @@ module CyborgHood
     def receive_error_action(message)
       cb = pop_callback(message)
       if cb
-        cb.call({:reply => :error, :reason => message.action_parameters[:error]})
+        error = message.action_parameters[:error]
+        exception = CyberError.new(error[:severity], error[:category], error[:message])
+        cb.call({:status => :error, :exception => exception})
       else
         send_error_protocol("received reply for unknown action")
       end
@@ -176,7 +188,7 @@ module CyborgHood
     def receive_reply_decline(message)
       cb = pop_callback(message)
       if cb
-        cb.call({:reply => :decline, :reason => message.action_parameters[:reason]})
+        cb.call({:status => :decline, :reason => message.action_parameters[:reason]})
       else
         send_error_protocol("received reply for unknown action")
       end
@@ -185,7 +197,7 @@ module CyborgHood
     def receive_reply_result(message)
       cb = pop_callback(message)
       if cb
-        cb.call({:reply => :ok, :result => message.action_parameters[:result]})
+        cb.call({:status => :ok, :result => message.action_parameters[:result]})
       else
         send_error_protocol("received reply for unknown action")
       end
