Browse Source

flaskr: report app init error instead of crashing

Improve error reporting of the application factory built during the tutorial
by not swallowing all OSError exceptions that could happen when trying to
create the instance folder.
pull/2930/head
Nechepso 6 years ago
parent
commit
0639bfaf23
  1. 6
      docs/tutorial/factory.rst
  2. 6
      examples/tutorial/flaskr/__init__.py

6
docs/tutorial/factory.rst

@ -35,6 +35,7 @@ directory should be treated as a package.
.. code-block:: python
:caption: ``flaskr/__init__.py``
import errno
import os
from flask import Flask
@ -58,8 +59,9 @@ directory should be treated as a package.
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
except OSError as e:
if e.errno != errno.EEXIST:
raise
# a simple page that says hello
@app.route('/hello')

6
examples/tutorial/flaskr/__init__.py

@ -1,3 +1,4 @@
import errno
import os
from flask import Flask
@ -23,8 +24,9 @@ def create_app(test_config=None):
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
except OSError as e:
if e.errno != errno.EEXIST:
raise
@app.route('/hello')
def hello():

Loading…
Cancel
Save