From a8699199713c51df196e6e2d0e803d983767664f Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Tue, 21 Dec 2021 19:43:28 +0000 Subject: Better error handling --- main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index aac9e51..c7bdd43 100644 --- a/main.py +++ b/main.py @@ -13,14 +13,14 @@ def get_location(args): config = ConfigParser() config_location = xdg_config_home().joinpath("auto-dark-mode", "config") - with open(config_location) as stream: - config.read_string("[auto-dark-mode]\n" + stream.read()) - config.read(config_location) - try: + with open(config_location) as stream: + config.read_string("[auto-dark-mode]\n" + stream.read()) + config.read(config_location) + latitude = config.getfloat("auto-dark-mode", "latitude") longitude = config.getfloat("auto-dark-mode", "longitude") - except NoOptionError: + except (FileNotFoundError, NoOptionError): sys.exit( f"Please supply latitude and longitude with the --latitude and --longitude flags, or set them in {config_location}" ) -- cgit v1.2.3