changeset 1003:05cc33d8e328

server: better error message on init issue / menu_json trouble + stop reactor in this case.
author Goffi <goffi@goffi.org>
date Fri, 05 Jan 2018 16:30:05 +0100
parents 990e80aa43a9
children 2f994b4e5a7d
files src/server/pages.py src/server/server.py
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/pages.py	Fri Jan 05 16:30:05 2018 +0100
+++ b/src/server/pages.py	Fri Jan 05 16:30:05 2018 +0100
@@ -250,14 +250,22 @@
         main_menu = []
         for menu in menus:
             if not menu:
-                raise ValueError(_(u"menu item can't be empty"))
+                msg = _(u"menu item can't be empty")
+                log.error(msg)
+                raise ValueError(msg)
             elif isinstance(menu, list):
                 if len(menu) != 2:
-                    raise ValueError(_(u"menu item as list must be in the formĀ [page_name, absolue URL]"))
+                    msg = _(u"menu item as list must be in the formĀ [page_name, absolue URL]")
+                    log.error(msg)
+                    raise ValueError(msg)
                 page_name, url = menu
             else:
                 page_name = menu
-                url = cls.getPageByName(page_name).url
+                try:
+                    url = cls.getPageByName(page_name).url
+                except KeyError as e:
+                    log.error(_(u"Can'find a named page ({msg}), please check menu_json in configuration.").format(msg=e))
+                    raise e
             main_menu.append((page_name, url))
         cls.main_menu = main_menu
 
--- a/src/server/server.py	Fri Jan 05 16:30:05 2018 +0100
+++ b/src/server/server.py	Fri Jan 05 16:30:05 2018 +0100
@@ -1488,12 +1488,16 @@
         self.renderer = template.Renderer(self)
         self.putChild('templates', ProtectedFile(self.renderer.base_dir))
 
+    def initEb(self, failure):
+        log.error(_(u"Init error: {msg}").format(msg=failure))
+        reactor.stop()
+        return failure
 
     def _bridgeCb(self):
         self.bridge.getReady(lambda: self.initialised.callback(None),
                              lambda failure: self.initialised.errback(Exception(failure)))
         self.initialised.addCallback(self.backendReady)
-        self.initialised.addErrback(lambda failure: log.error(u"Init error: %s" % failure))
+        self.initialised.addErrback(self.initEb)
 
     def _bridgeEb(self, failure):
         log.error(u"Can't connect to bridge: {}".format(failure))