From d3998aa1cd1bc3a96ed47f6f0ea48c974da045f8 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 30 Aug 2018 08:58:54 -0500 Subject: [PATCH] Improved error handling for configs that don't exist. --- geoffrey/BotConfig.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/geoffrey/BotConfig.py b/geoffrey/BotConfig.py index 1bbc9fe..0326892 100644 --- a/geoffrey/BotConfig.py +++ b/geoffrey/BotConfig.py @@ -1,6 +1,5 @@ import codecs import configparser -import os def create_config(config, path): @@ -35,9 +34,9 @@ def create_config(config, path): def read_config(path): config = configparser.ConfigParser() - config.read_file(codecs.open(path, "r", "utf8")) - - if len(config.sections()) == 0: + try: + config.read_file(codecs.open(path, "r", "utf8")) + except FileNotFoundError: create_config(config, path) print("Config generated.") quit(0)