Module: tools Branch: master Commit: e2e5c22854e7ee6fbaaa2e6c321c95f0008a4bef URL: https://gitlab.winehq.org/winehq/tools/-/commit/e2e5c22854e7ee6fbaaa2e6c321c...
Author: Jeremy White jwhite@codeweavers.com Date: Tue Jul 19 08:53:33 2022 -0500
gitlab: Catch a common exception while parsing settings.
---
gitlab/gitlab-to-mail/util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/gitlab/gitlab-to-mail/util.py b/gitlab/gitlab-to-mail/util.py index aef43c6d..629b20c0 100644 --- a/gitlab/gitlab-to-mail/util.py +++ b/gitlab/gitlab-to-mail/util.py @@ -20,9 +20,15 @@ def fetch_all(url, settings): class Settings: def __init__(self, fname): self.cp = configparser.ConfigParser() - if len(self.cp.read(fname)) == 0: - print(f"Error: invalid configuration in {fname}.", file=sys.stderr) + try: + if len(self.cp.read(fname)) == 0: + print(f"Error: invalid or missing configuration in {fname}.", file=sys.stderr) + sys.exit(1) + except configparser.MissingSectionHeaderError as e: + print(f"Error: missing section header parsing {fname}") + print(e) sys.exit(1) + for s in ['DATABASE', 'GITLAB_TOKEN', 'GITLAB_URL', 'GITLAB_PROJECT_NAME', 'BRIDGE_FROM_EMAIL', 'BRIDGE_TO_EMAIL', 'BRIDGE_TAG', 'SMTP_DOMAIN', 'SMTP_USER', 'SMTP_PASSWORD']: