refactor: Extract display_config_file_errors().
This will be useful for handling errors with third party config files.
This commit is contained in:
parent
8a15452525
commit
57c90ddca0
|
@ -200,6 +200,12 @@ def is_private_message_from_another_user(message_dict, current_user_id):
|
||||||
return current_user_id != message_dict['sender_id']
|
return current_user_id != message_dict['sender_id']
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def display_config_file_errors(error_msg, config_file):
|
||||||
|
# type: (str, str) -> None
|
||||||
|
file_contents = open(config_file).read()
|
||||||
|
print('\nERROR: {} seems to be broken:\n\n{}'.format(config_file, file_contents))
|
||||||
|
print('\nMore details here:\n\n{}\n'.format(error_msg))
|
||||||
|
|
||||||
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
||||||
# type: (Any, bool, str, str) -> Any
|
# type: (Any, bool, str, str) -> Any
|
||||||
#
|
#
|
||||||
|
@ -221,9 +227,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
||||||
try:
|
try:
|
||||||
client = Client(config_file=config_file, client=client_name)
|
client = Client(config_file=config_file, client=client_name)
|
||||||
except configparser.Error as e:
|
except configparser.Error as e:
|
||||||
file_contents = open(config_file).read()
|
display_config_file_errors(str(e), config_file)
|
||||||
print('\nERROR: {} seems to be broken:\n\n{}'.format(config_file, file_contents))
|
|
||||||
print('\nMore details here:\n\n' + str(e) + '\n')
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
bot_dir = os.path.dirname(lib_module.__file__)
|
bot_dir = os.path.dirname(lib_module.__file__)
|
||||||
|
|
Loading…
Reference in a new issue