From cfb4e94e0342e71e072f2e599635b472990d4f0e Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Tue, 23 Aug 2016 13:20:39 +0200 Subject: [PATCH 1/4] feat(import_app): print original exception on AppImportError --- gunicorn/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index a011fb853..aec49dfbd 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -387,6 +387,9 @@ def import_app(module): try: app = eval(obj, mod.__dict__) except NameError: + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback, + limit=3, file=sys.stdout) raise AppImportError("Failed to find application: %r" % module) if app is None: @@ -565,4 +568,4 @@ def app(environ, start_response): ]) return [msg] - return app \ No newline at end of file + return app From b4f38a50e3da395b06aeed295e9d613baf104431 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Tue, 23 Aug 2016 13:28:18 +0200 Subject: [PATCH 2/4] Update util.py --- gunicorn/util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index aec49dfbd..5da68f5aa 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -388,8 +388,7 @@ def import_app(module): app = eval(obj, mod.__dict__) except NameError: exc_type, exc_value, exc_traceback = sys.exc_info() - traceback.print_exception(exc_type, exc_value, exc_traceback, - limit=3, file=sys.stdout) + traceback.print_exception(exc_type, exc_value, exc_traceback) raise AppImportError("Failed to find application: %r" % module) if app is None: From 48dff82a570f4efe45082ce8b3477bf1a56f8ec2 Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Mon, 3 Oct 2016 09:37:55 +0200 Subject: [PATCH 3/4] use star args not to keep a dependency on exc_traceback --- gunicorn/util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index 5da68f5aa..bf679443e 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -387,8 +387,7 @@ def import_app(module): try: app = eval(obj, mod.__dict__) except NameError: - exc_type, exc_value, exc_traceback = sys.exc_info() - traceback.print_exception(exc_type, exc_value, exc_traceback) + traceback.print_exception(*sys.exc_info()) raise AppImportError("Failed to find application: %r" % module) if app is None: From 14d98e3a6177148f4059b3e631a8d69cf48d1f5b Mon Sep 17 00:00:00 2001 From: Patrick Browne Date: Mon, 3 Oct 2016 09:38:52 +0200 Subject: [PATCH 4/4] checking debug level not to expose sensitive information --- gunicorn/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index bf679443e..3bbb92c3c 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -24,6 +24,7 @@ import errno import warnings import cgi +import logging from gunicorn.errors import AppImportError from gunicorn.six import text_type @@ -384,10 +385,12 @@ def import_app(module): mod = sys.modules[module] + is_debug = logging.root.level == logging.DEBUG try: app = eval(obj, mod.__dict__) except NameError: - traceback.print_exception(*sys.exc_info()) + if is_debug: + traceback.print_exception(*sys.exc_info()) raise AppImportError("Failed to find application: %r" % module) if app is None: