Mercurial > cgi-bin > hgweb.cgi > tincan
diff tincan.py @ 18:e88ab99914cf draft
More improvements to the error reportage.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 20 May 2019 08:40:56 -0700 |
parents | 8186de188daf |
children | 5d9a1b82251a |
line wrap: on
line diff
--- a/tincan.py Mon May 20 07:34:46 2019 -0700 +++ b/tincan.py Mon May 20 08:40:56 2019 -0700 @@ -340,6 +340,11 @@ return e except Exception as e: traceback.print_exc() + # Bottle doesn't allow error handlers to themselves cause + # errors, most likely as a measure to prevent looping. So + # this will cause a "Critical error while processing request" + # page to be displayed, and any installed error pages to be + # ignored. raise bottle.HTTPError(status=500, exception=e) class _TinCanRoute(object): @@ -596,13 +601,23 @@ """ # Sanity checks if not self.urlroot.startswith("/"): - raise TinCanError("urlroot must be absolute") + self.errors = 1 + self.logger("urlroot not absolute: {0!r}".format(self.urlroot)) + return self if not os.path.isdir(self.fsroot): - raise TinCanError("no such directory: {0!r}".format(self.fsroot)) - # Make WEB-INF, if needed + self.errors = 1 + self.logger("no such directory: {0!r}".format(self.fsroot)) + return self + # Make any needed directories. Refuse to launch things that don't + # contain WEB-INF, to prevent accidental launches of undesired + # directory trees containing sensitive files. winf = os.path.join(self.fsroot, _WINF) + if not os.path.isdir(winf): + self.errors = 1 + self.logger("no WEB-INF directory in {0!r}".format(self.fsroot)) + return self lib = os.path.join(winf, "lib") - for i in [ winf, lib ]: + for i in [ lib ]: if not os.path.isdir(i): os.mkdir(i) # Add our private lib directory to sys.path