Skip to content
Permalink
Browse files

Added proper error messages in cases where app cannot be loaded. (#4990)

Previously we'd simply crash with an exception. Now a proper error message is displayed.
  • Loading branch information...
thedrow authored and auvipy committed Jan 29, 2019
1 parent dc1d895 commit acd6025b7dc4db112a31020686fc8b15e1722c67
Showing with 20 additions and 1 deletion.
  1. +20 −1 celery/bin/base.py
@@ -50,6 +50,16 @@
Try --help?
"""

UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND = """
Unable to load celery application.
The module {0} was not found.
"""

UNABLE_TO_LOAD_APP_APP_MISSING = """
Unable to load celery application.
{0}
"""

find_long_opt = re.compile(r'.+?(--.+?)(?:\s|,|$)')
find_rst_ref = re.compile(r':\w+:`(.+?)`')
find_rst_decl = re.compile(r'^\s*\.\. .+?::.+$')
@@ -270,7 +280,16 @@ def execute_from_commandline(self, argv=None):

# Dump version and exit if '--version' arg set.
self.early_version(argv)
argv = self.setup_app_from_commandline(argv)
try:
argv = self.setup_app_from_commandline(argv)
except ModuleNotFoundError as e:
self.on_error(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))
return EX_FAILURE
except AttributeError as e:
msg = e.args[0].capitalize()
self.on_error(UNABLE_TO_LOAD_APP_APP_MISSING.format(msg))
return EX_FAILURE

self.prog_name = os.path.basename(argv[0])
return self.handle_argv(self.prog_name, argv[1:])

0 comments on commit acd6025

Please sign in to comment.
You can’t perform that action at this time.