Merge pull request #2209 from svenstaro/print-stacktrace-on-cli-error

Print a stacktrace on CLI error (closes #2208)
This commit is contained in:
David Lord 2017-03-16 13:43:01 -07:00 committed by GitHub
commit 6efea346dd
2 changed files with 21 additions and 1 deletions

View file

@ -11,6 +11,7 @@
import os
import sys
import traceback
from threading import Lock, Thread
from functools import update_wrapper
@ -368,7 +369,9 @@ class FlaskGroup(AppGroup):
# want the help page to break if the app does not exist.
# If someone attempts to use the command we try to create
# the app again and this will give us the error.
pass
# However, we will not do so silently because that would confuse
# users.
traceback.print_exc()
return sorted(rv)
def main(self, *args, **kwargs):

View file

@ -191,3 +191,20 @@ def test_flaskgroup():
result = runner.invoke(cli, ['test'])
assert result.exit_code == 0
assert result.output == 'flaskgroup\n'
def test_print_exceptions():
"""Print the stacktrace if the CLI."""
def create_app(info):
raise Exception("oh no")
return Flask("flaskgroup")
@click.group(cls=FlaskGroup, create_app=create_app)
def cli(**params):
pass
runner = CliRunner()
result = runner.invoke(cli, ['--help'])
assert result.exit_code == 0
assert 'Exception: oh no' in result.output
assert 'Traceback' in result.output