Closed rochacbruno closed 4 years ago
Anything that improves help messages is great.
Looks better in flask 1.0.2, so maybe we can close this?
help
option~/flask flask --help
Traceback (most recent call last):
File "/Users/username/.local/share/virtualenvs/flask-C1e3YqV7/lib/python3.7/site-packages/flask/cli.py", line 529, in list_commands
rv.update(info.load_app().cli.list_commands(ctx))
File "/Users/username/.local/share/virtualenvs/flask-C1e3YqV7/lib/python3.7/site-packages/flask/cli.py", line 384, in load_app
'Could not locate a Flask application. You did not provide '
flask.cli.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.
~/flask flask run
* 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 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.
Please keep discussions in English, we can't support other languages.
The various exception messages, including when the env var wasn't set and a default wasn't found, have improved over time. That one now reads:
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.
Tracebacks were added in #2208 to avoid confusion caused by the previous behavior where list_commands()
hid errors completely.
After reviewing the code, I think we should show only the error message for NoAppException
, while still showing the full traceback for other exceptions. Tracebacks for loading errors are no longer helpful as they only show Flask internals. We still want to show the help text because the flask --help
command still has useful output.
Expected Behavior
As there is the support for
lazy loading
the app, when runningflask
CLI without providing the proper environment variables we must see a better warning instead of raw exception.Tell us what should happen.
we should see a better warning or message pointing to the problem
Actual Behavior
Tell us what happens instead.
we see traceback before the help message
The same happens to
run
The
Error: Could not import "app".
could includeWARNING: You need to define the app e.g: export FLASK_APP=app.py
Suggestion
We could check the existence of
FLASK_APP
envvar before running any of the commands in the Group Cli, if FLASK_APP does not exist the dispatch of commands never happens.Environment