From 197a9e82a282b00c271cb42240aa751e76542181 Mon Sep 17 00:00:00 2001
From: Emmanuel Garette <egarette@cadoles.com>
Date: Wed, 25 Mar 2020 09:13:29 +0100
Subject: [PATCH] raise if a 'publish' function failed

---
 src/risotto/dispatcher.py | 51 +++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/risotto/dispatcher.py b/src/risotto/dispatcher.py
index 3928ef0..e9244c7 100644
--- a/src/risotto/dispatcher.py
+++ b/src/risotto/dispatcher.py
@@ -333,32 +333,31 @@ class Dispatcher(register.RegisterDispatcher,
 
             kw['risotto_context'] = risotto_context
             returns = await function(self.injected_self[function_obj['module']], **kw)
-            else:
-                if risotto_context.type == 'rpc':
-                    # valid returns
-                    await self.valid_call_returns(risotto_context,
-                                                  function,
-                                                  returns,
-                                                  kwargs)
-                # log the success
-                await log.info_msg(risotto_context,
-                                   {'arguments': kwargs,
-                                    'returns': returns},
-                                   info_msg)
-                # notification
-                if function_obj.get('notification'):
-                    notif_version, notif_message = function_obj['notification'].split('.', 1)
-                    if not isinstance(returns, list):
-                        send_returns = [returns]
-                    else:
-                        send_returns = returns
-                    for ret in send_returns:
-                        await self.publish(notif_version,
-                                           notif_message,
-                                           risotto_context,
-                                           **ret)
-                if risotto_context.type == 'rpc':
-                    return returns
+            if risotto_context.type == 'rpc':
+                # valid returns
+                await self.valid_call_returns(risotto_context,
+                                              function,
+                                              returns,
+                                              kwargs)
+            # log the success
+            await log.info_msg(risotto_context,
+                               {'arguments': kwargs,
+                                'returns': returns},
+                               info_msg)
+            # notification
+            if function_obj.get('notification'):
+                notif_version, notif_message = function_obj['notification'].split('.', 1)
+                if not isinstance(returns, list):
+                    send_returns = [returns]
+                else:
+                    send_returns = returns
+                for ret in send_returns:
+                    await self.publish(notif_version,
+                                       notif_message,
+                                       risotto_context,
+                                       **ret)
+            if risotto_context.type == 'rpc':
+                return returns
 
 
 dispatcher = Dispatcher()