manage.py: Print CommandError exceptions cleanly.

Django, by default, prints these exceptions as a giant traceback,
which is really ugly and scary to sysadmins.  We really just want to
print the error message to stdout for convenient viewing by the user.
This commit is contained in:
Tim Abbott
2017-07-07 11:50:50 -07:00
parent cd4f35abdf
commit a9d52052f0

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import logging
@@ -16,6 +19,7 @@ if __name__ == "__main__":
os.environ.setdefault("PYTHONSTARTUP", os.path.join(BASE_DIR, "scripts/lib/pythonrc.py"))
from django.conf import settings
from django.core.management.base import CommandError
logger = logging.getLogger("zulip.management")
subprocess.check_call([os.path.join(BASE_DIR, "scripts", "lib", "log-management-command"),
@@ -26,4 +30,8 @@ if __name__ == "__main__":
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
try:
execute_from_command_line(sys.argv)
except CommandError as e:
print(e, file=sys.stderr)
sys.exit(1)