<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Only the error message / usage information being printed</p>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">A traceback shows up above the usage information.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Python version: 2.7.14</li>
<li>Flask version: 1.0.2</li>
<li>Werkzeug version: 0.14.1</li>
</ul>
<hr>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[adrian@blackhole:/tmp]&gt; virtualenv testenv
New python executable in /tmp/testenv/bin/python2.7
Also creating executable in /tmp/testenv/bin/python
Installing setuptools, pip, wheel...done.

[adrian@blackhole:/tmp]&gt; ./testenv/bin/pip install flask
Collecting flask
  Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
Collecting Werkzeug&gt;=0.14 (from flask)
  Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Collecting click&gt;=5.1 (from flask)
  Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl
Collecting itsdangerous&gt;=0.24 (from flask)
Collecting Jinja2&gt;=2.10 (from flask)
  Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.10-&gt;flask)
Installing collected packages: Werkzeug, click, itsdangerous, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0.2 itsdangerous-0.24


[adrian@blackhole:/tmp]&gt; ./testenv/bin/flask
Traceback (most recent call last):
  File &quot;/tmp/testenv/lib/python2.7/site-packages/flask/cli.py&quot;, line 529, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File &quot;/tmp/testenv/lib/python2.7/site-packages/flask/cli.py&quot;, line 384, in load_app
    'Could not locate a Flask application. You did not provide '
NoAppException: Could not locate a Flask application. You did not provide the &quot;FLASK_APP&quot; environment variable, and a &quot;wsgi.py&quot; or &quot;app.py&quot; module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=hello.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context."><pre class="notranslate"><code class="notranslate">[adrian@blackhole:/tmp]&gt; virtualenv testenv
New python executable in /tmp/testenv/bin/python2.7
Also creating executable in /tmp/testenv/bin/python
Installing setuptools, pip, wheel...done.

[adrian@blackhole:/tmp]&gt; ./testenv/bin/pip install flask
Collecting flask
  Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
Collecting Werkzeug&gt;=0.14 (from flask)
  Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Collecting click&gt;=5.1 (from flask)
  Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl
Collecting itsdangerous&gt;=0.24 (from flask)
Collecting Jinja2&gt;=2.10 (from flask)
  Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl
Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.10-&gt;flask)
Installing collected packages: Werkzeug, click, itsdangerous, MarkupSafe, Jinja2, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0.2 itsdangerous-0.24


[adrian@blackhole:/tmp]&gt; ./testenv/bin/flask
Traceback (most recent call last):
  File "/tmp/testenv/lib/python2.7/site-packages/flask/cli.py", line 529, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File "/tmp/testenv/lib/python2.7/site-packages/flask/cli.py", line 384, in load_app
    'Could not locate a Flask application. You did not provide '
NoAppException: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=hello.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context.
</code></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">As there is the support for <code class="notranslate">lazy loading</code> the app, when running <code class="notranslate">flask</code> CLI without providing the proper environment variables we must see a better warning instead of raw exception.</p>
<p dir="auto">Tell us what should happen.</p>
<p dir="auto"><strong>we should see a better warning or message pointing to the problem</strong></p>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# there is no FLASK_APP env var
$ flask --help
WARNING: You need to define the app e.g: `export FLASK_APP=app.py`"><pre class="notranslate"># there is no FLASK_APP env var
$ flask --help
<span class="pl-en">WARNING</span>: <span class="pl-s">You need to define the app e.g: `export FLASK_APP=app.py`</span></pre></div>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">Tell us what happens instead.</p>
<p dir="auto"><strong>we see traceback before the help message</strong></p>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# there is no FLASK_APP env var
$ flask --help                                                               Sat 28 Apr 2018 01:25:50 PM -03
Traceback (most recent call last):
  File &quot;~Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py&quot;, line 235, in locate_app
    __import__(module_name)
ModuleNotFoundError: No module named 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py&quot;, line 529, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File &quot;~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py&quot;, line 372, in load_app
    app = locate_app(self, import_name, name)
  File &quot;~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py&quot;, line 246, in locate_app
    'Could not import &quot;{name}&quot;.'.format(name=module_name)
flask.cli.NoAppException: Could not import &quot;app&quot;.
Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=hello.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context.
"><pre class="notranslate"># there is no FLASK_APP env var
$ flask --help                                                               Sat 28 Apr 2018 01:25:50 PM -03
Traceback (most recent call last):
  File <span class="pl-s">"~Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py"</span>, line <span class="pl-c1">235</span>, in <span class="pl-en">locate_app</span>
    <span class="pl-c1">__import__</span>(module_name)
<span class="pl-en">ModuleNotFoundError</span>: <span class="pl-s">No module named 'app'</span>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File <span class="pl-s">"~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py"</span>, line <span class="pl-c1">529</span>, in <span class="pl-en">list_commands</span>
    rv.update(info.load_app().cli.list_commands(ctx))
  File <span class="pl-s">"~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py"</span>, line <span class="pl-c1">372</span>, in <span class="pl-en">load_app</span>
    app <span class="pl-k">=</span> locate_app(<span class="pl-c1">self</span>, import_name, name)
  File <span class="pl-s">"~/Projects/personal/flasgger/venv/lib/python3.6/site-packages/flask/cli.py"</span>, line <span class="pl-c1">246</span>, in <span class="pl-en">locate_app</span>
    <span class="pl-s"><span class="pl-pds">'</span>Could not import "<span class="pl-c1">{name}</span>".<span class="pl-pds">'</span></span>.format(<span class="pl-v">name</span><span class="pl-k">=</span>module_name)
<span class="pl-en">flask.cli.NoAppException</span>: <span class="pl-s">Could not import "app".</span>
<span class="pl-en">Usage</span>: <span class="pl-s">flask [OPTIONS] COMMAND [ARGS]...</span>

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    <span class="pl-ii">$</span> export <span class="pl-c1">FLASK_APP</span><span class="pl-k">=</span>hello.py
    <span class="pl-ii">$</span> export <span class="pl-c1">FLASK_ENV</span><span class="pl-k">=</span>development
    <span class="pl-ii">$</span> flask run

<span class="pl-en">Options</span>:
  --version  Show the flask version
  --help     Show this message and exit.

<span class="pl-en">Commands</span>:
  routes  Show the routes for the app.
  run     Runs a development server.
  shell   Runs a shell in the app context.
</pre></div>
<p dir="auto">The same happens to <code class="notranslate">run</code></p>
<div class="highlight highlight-text-python-traceback notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ flask run                                                          429ms  Sat 28 Apr 2018 01:32:48 PM -03
 * Serving Flask app &quot;app.py&quot;
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: Could not import &quot;app&quot;."><pre class="notranslate">$ flask run                                                          429ms  Sat 28 Apr 2018 01:32:48 PM -03
 * Serving Flask app "app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
<span class="pl-en">Usage</span>: <span class="pl-s">flask run [OPTIONS]</span>

<span class="pl-en">Error</span>: <span class="pl-s">Could not import "app".</span></pre></div>
<p dir="auto">The <code class="notranslate">Error: Could not import "app".</code> could include <code class="notranslate">WARNING: You need to define the app e.g: export FLASK_APP=app.py</code></p>
<h3 dir="auto">Suggestion</h3>
<p dir="auto">We could check the existence of <code class="notranslate">FLASK_APP</code> envvar before running any of the commands in the Group Cli, if FLASK_APP does not exist the dispatch of commands never happens.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Python version: 3.6.0</li>
<li>Flask version: Flask==1.0</li>
<li>Werkzeug version: Werkzeug==0.14.1</li>
<li>Click: click==6.7</li>
</ul>