Skip to content

Commit

Permalink
Merge pull request pallets#2209 from svenstaro/print-stacktrace-on-cl…
Browse files Browse the repository at this point in the history
…i-error

Print a stacktrace on CLI error (closes pallets#2208)
  • Loading branch information
davidism authored Mar 16, 2017
2 parents 1add1f8 + ed17bc1 commit 6efea34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import os
import sys
import traceback
from threading import Lock, Thread
from functools import update_wrapper

Expand Down Expand Up @@ -368,7 +369,9 @@ def list_commands(self, ctx):
# 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):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,20 @@ def test():
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

0 comments on commit 6efea34

Please sign in to comment.