Skip to content

Commit ec5efcf

Browse files
committed
fix: catch exception if config file cannot be found
1 parent 9ac7c43 commit ec5efcf

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

beetsstatistics.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class DBQueryError(Exception):
1919
pass
2020

2121

22+
class ConfigFileNotFoundError(Exception):
23+
pass
24+
25+
2226
class Album:
2327
def __repr__(self):
2428
return f"ID: {self.id}, Title: {self.title}, Tracks: {self.tracks}/{self.tracks_total} ({self.complete_percentage}%), Album artist: {self.album_artist}, Genre: {self.genre}, Year: {self.year} ({self.original_year}), Album Art: {self.album_cover}"
@@ -54,11 +58,14 @@ def get_db_file_name(self):
5458
if self.db_file is not None:
5559
return self.db_file
5660
db_config_key = "library"
57-
# TODO Catch exception if file does not exist
5861
config_file_name = os.path.expanduser("~/.config/beets/config.yaml")
59-
with open(config_file_name, "r") as file:
60-
config = yaml.safe_load(file)
61-
return os.path.expanduser(config[db_config_key])
62+
try:
63+
# TODO Catch exception if file does not exist
64+
with open(config_file_name, "r") as file:
65+
config = yaml.safe_load(file)
66+
return os.path.expanduser(config[db_config_key])
67+
except Exception as e:
68+
raise ConfigFileNotFoundError from e
6269

6370
def get_db_connection(self):
6471
if self.connection is not None:

0 commit comments

Comments
 (0)