From ac9e35123c86d9cbd176948558aa26a992121b51 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 8 Jun 2022 16:34:28 +0200 Subject: [PATCH] better error message when cfg file does not exist --- frappyman.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frappyman.py b/frappyman.py index 948b938..edbeab6 100644 --- a/frappyman.py +++ b/frappyman.py @@ -23,7 +23,7 @@ import sys import os from glob import glob -from os.path import join, isdir, basename, expanduser +from os.path import join, isdir, basename, expanduser, exists from configparser import ConfigParser from servicemanager.base import ServiceManager, ServiceDown, UsageError @@ -51,7 +51,13 @@ class FrappyManager(ServiceManager): cfgparser.optionxform = str cfgfile = self.env[ins]['FRAPPY_CONFIG_FILE'].replace('', service) cfgparser.read(cfgfile) - for cfgpath in cfgparser['FRAPPY']['confdir'].split(os.pathsep): + try: + section = cfgparser['FRAPPY'] + except KeyError: + if exists(cfgfile): + raise KeyError('%s has no FRAPPY section' % cfgfile) + raise FileNotFoundError('%s does not exist' % cfgfile) + for cfgpath in section['confdir'].split(os.pathsep): if cfgpath.endswith(''): cfgpaths.append(cfgpath[:-6] + service) else: