Skip to content

Commit

Permalink
fix: better error message when flask not installed
Browse files Browse the repository at this point in the history
The dependencies for the AiiDA REST API are currently not installed by
default - only when users request the `rest` extra.

When users were starting the REST API without installing the extra, they
were greeted by an unhelpful/unexpected error message

	ModuleNotFoundError: No module named 'flask_restful'

Here we catch ImportErrors upon starting the REST API and provide an
error message that includes instructions on how to remedy the situation.
For cases where the ImportError has another cause, the original
exception is carried along as well.
  • Loading branch information
ltalirz committed Feb 25, 2022
1 parent e36f350 commit 8d91e2e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions aiida/cmdline/commands/cmd_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ def restapi(hostname, port, config_dir, debug, wsgi_profile, posting):
from aiida.restapi.run_api import run_api

# Invoke the runner
run_api(
hostname=hostname,
port=port,
config=config_dir,
debug=debug,
wsgi_profile=wsgi_profile,
posting=posting,
)
try:
run_api(
hostname=hostname,
port=port,
config=config_dir,
debug=debug,
wsgi_profile=wsgi_profile,
posting=posting,
)
except ImportError as exc:
raise ImportError(
'Failed to import modules required for the REST API. '
'You may need to install the `rest` extra, e.g. via `pip install aiida-core[rest]`.'
) from exc

0 comments on commit 8d91e2e

Please sign in to comment.