Skip to content

Commit cda34a4

Browse files
committed
JsonDatabase: improve exception message
1 parent 332d6d5 commit cda34a4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lazy_dataset/database.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,18 @@ def __reduce__(self):
286286
@property
287287
def data(self):
288288
if self._data is None:
289+
def read_text(path):
290+
try:
291+
path = Path(path)
292+
except TypeError:
293+
if isinstance(path, dict):
294+
raise TypeError(f'{self.__class__.__qualname__} got a {type(path)} as json_path. Did you mean to use DictDatabase?')
295+
else:
296+
raise
297+
return path.expanduser().read_text()
298+
289299
self._data = _merge_database_dicts(*[
290-
json.loads(Path(path).expanduser().read_text())
300+
json.loads(read_text(path))
291301
for path in self._json_path
292302
])
293303

0 commit comments

Comments
 (0)