Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Print a stacktrace on CLI error (closes #2208)

authored by David Lord · committed by GitHub · parents 1add1f8, ed17bc1 · Browse files · 2 files+21 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−1 removed

  • tests:+17 added−0 removed
  • other:+4 added−1 removed

2 files+21 added−1 removed

modified:flask/cli.py+4 added-1 removed
9 unmodified lines
10"""1112import os13import sys14import traceback15from threading import Lock, Thread16from functools import update_wrapper1718import click
349 unmodified lines
368 # Here we intentionally swallow all exceptions as we don't369 # want the help page to break if the app does not exist.370 # If someone attempts to use the command we try to create371 # the app again and this will give us the error.371 pass372 # However, we will not do so silently because that would confuse373 # users.374 traceback.print_exc()375 return sorted(rv)376377 def main(self, *args, **kwargs):378 obj = kwargs.get('obj')
149 unmodified lines
modified:tests/test_cli.py+17 added
189 unmodified lines
190 runner = CliRunner()191 result = runner.invoke(cli, ['test'])192 assert result.exit_code == 0193 assert result.output == 'flaskgroup\n'194195196def test_print_exceptions():197 """Print the stacktrace if the CLI."""198 def create_app(info):199 raise Exception("oh no")200 return Flask("flaskgroup")201202 @click.group(cls=FlaskGroup, create_app=create_app)203 def cli(**params):204 pass205206 runner = CliRunner()207 result = runner.invoke(cli, ['--help'])208 assert result.exit_code == 0209 assert 'Exception: oh no' in result.output210 assert 'Traceback' in result.output