summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Ball <git@michaelball.name>2021-12-21 19:43:28 +0000
committerMichaël Ball <git@michaelball.name>2021-12-21 19:43:28 +0000
commita8699199713c51df196e6e2d0e803d983767664f (patch)
treeddec07355fc0fec75cb76ed7c88dae002fbb750b
parentcf4018d97cd7c46ffa171e2f6b84e6a50e27a772 (diff)
Better error handling
-rw-r--r--main.py10
1 files changed, 5 insertions, 5 deletions
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}"
)