Skip to content

Commit

Permalink
Fix config error handling in roundrobin.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Janzert committed Jun 3, 2021
1 parent 12ab4f1 commit 6156340
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pyrimaa/roundrobin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

log = logging.getLogger("roundrobin")

class ConfigError(Exception):
pass


def run_bot(bot, config, global_options):
cmdline = config.get(bot['name'], "cmdline")
Expand Down Expand Up @@ -108,13 +111,11 @@ class NotSet:

config = ConfigParser()
if config.read(args.config) != [args.config]:
print("Could not open '%s'" % (args.config, ))
return 1
raise ConfigError("Could not open '%s'" % (args.config, ))
args.ini = config
args.bot_sections = set(config.sections())
if "global" not in args.bot_sections:
print("Did not find expected 'global' section in configuration file.")
return 1
raise ConfigError("Did not find expected 'global' section in configuration file.")
args.bot_sections.remove('global')

try:
Expand Down Expand Up @@ -174,7 +175,12 @@ class NotSet:


def main(args=None):
cfg = get_config(args)
try:
cfg = get_config(args)
except ConfigError as exc:
print(exc)
return 1

if cfg.rounds:
print("Number of rounds: %d" % (cfg.rounds, ))
else:
Expand Down

0 comments on commit 6156340

Please sign in to comment.