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.
This commit is contained in:
parent
3d05b88cc2
commit
c85b42be9f
|
@ -2,7 +2,9 @@ import configparser
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from configparser import MissingSectionHeaderError
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from typing import Any, Dict, Union, List, Optional
|
from typing import Any, Dict, Union, List, Optional
|
||||||
|
@ -141,7 +143,12 @@ def handle_bot() -> Union[str, BadRequest, Unauthorized]:
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
options = parse_args()
|
options = parse_args()
|
||||||
global bots_config
|
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())
|
available_bots = list(bots_config.keys())
|
||||||
bots_lib_modules = load_lib_modules(available_bots)
|
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
|
third_party_bot_conf = parse_config_file(options.bot_config_file) if options.bot_config_file is not None else None
|
||||||
|
|
Loading…
Reference in a new issue