From c85b42be9f9259ecc877d31fa5dcce2987f3fd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20H=C3=B6nig?= Date: Fri, 1 Jun 2018 14:17:34 +0200 Subject: [PATCH] botserver: Exit with helpful output if botserverrc is invalid. If the botserverrc file contains empty section headers, it is very likely that the user forgot to edit the file. This reminds them to do so. --- zulip_botserver/zulip_botserver/server.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index a599abd..eaed323 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -2,7 +2,9 @@ import configparser import logging import json import os +import sys +from configparser import MissingSectionHeaderError from flask import Flask, request from importlib import import_module from typing import Any, Dict, Union, List, Optional @@ -141,7 +143,12 @@ def handle_bot() -> Union[str, BadRequest, Unauthorized]: def main() -> None: options = parse_args() global bots_config - bots_config = read_config_file(options.config_file, options.bot_name) + try: + bots_config = read_config_file(options.config_file, options.bot_name) + except MissingSectionHeaderError: + sys.exit("Error: Your Botserver config file `{0}` contains an empty section header!\n" + "You need to write the names of the bots you want to run in the " + "section headers of `{0}`.".format(options.config_file)) available_bots = list(bots_config.keys()) bots_lib_modules = load_lib_modules(available_bots) third_party_bot_conf = parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None