Skip to content

Commit

Permalink
ref: improve settings loading exception reporting
Browse files Browse the repository at this point in the history
Deduplicate the one exception we make.

Also now instead of just eating the catchall exception, we raise from it
so that you have slightly more insight into its cause
  • Loading branch information
NickCrews committed Sep 16, 2022
1 parent 241c0a6 commit 83a2e89
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions dedupe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ def _load_settings(
# Make a copy so we can read it multiple times
settings_file = BytesIO(settings_file.read())
settings_file.seek(0)
catchall_exception = SettingsFileLoadingException(
"Something has gone wrong with loading the settings file. "
"Try deleting the file"
)
try:
version = pickle.load(settings_file)
if not isinstance(version, int):
Expand All @@ -1021,15 +1025,9 @@ def _load_settings(
"install that library: `pip install rlr`"
)
else:
raise SettingsFileLoadingException(
"Something has gone wrong with loading the settings file. "
"Try deleting the file"
) from exc
except: # noqa: E722
raise SettingsFileLoadingException(
"Something has gone wrong with loading the settings file. "
"Try deleting the file"
)
raise
except Exception as exc:
raise catchall_exception from exc

@staticmethod
def _load_settings_v0(
Expand Down

0 comments on commit 83a2e89

Please sign in to comment.