Browse Source

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

Print a stacktrace on CLI error (closes #2208)
pull/2210/head
David Lord 8 years ago committed by GitHub
parent
commit
6efea346dd
  1. 5
      flask/cli.py
  2. 17
      tests/test_cli.py

5
flask/cli.py

@ -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):

17
tests/test_cli.py

@ -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

Loading…
Cancel
Save