# HG changeset patch # User David Barts # Date 1558366856 25200 # Node ID e88ab99914cfa89a05f4af0270ae475b29c5d9c2 # Parent 8186de188daf29907b18b63ee59fd1cf34b4d9ec More improvements to the error reportage. diff -r 8186de188daf -r e88ab99914cf launch --- a/launch Mon May 20 07:34:46 2019 -0700 +++ b/launch Mon May 20 08:40:56 2019 -0700 @@ -25,6 +25,6 @@ app, errors = launch(fsroot=args.directory, urlroot=args.path) if errors: sys.stderr.write("{0}: {1} error{2} detected, aborting\n".format( - sys.argv[0], errors, "" if errors == 1 else "s")) + MYNAME, errors, "" if errors == 1 else "s")) sys.exit(1) app.run(host=args.bind, port=args.port) diff -r 8186de188daf -r e88ab99914cf tincan.py --- 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