Skip to content

Commit

Permalink
Unify error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 committed Jan 14, 2025
1 parent 0442d88 commit c4406ca
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/spikeinterface/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ def load(file_path: Union[str, Path], base_folder: Optional[Union[Path, str, boo
* save (...) a folder which contain data + json (or pickle) + metadata.
"""
error_msg = (
f"{file_path} is not a file or a folder. It should point to either a json, pickle file or a "
"folder that is the result of extractor.save(...)"
)
if not is_path_remote(file_path):
file_path = Path(file_path)

Expand All @@ -776,7 +780,8 @@ def load(file_path: Union[str, Path], base_folder: Optional[Union[Path, str, boo
with open(file_path, "rb") as f:
d = pickle.load(f)
else:
raise ValueError(f"Impossible to load {file_path}")
raise ValueError(error_msg)

if "warning" in d:
print("The extractor was not serializable to file")
return None
Expand All @@ -793,27 +798,22 @@ def load(file_path: Union[str, Path], base_folder: Optional[Union[Path, str, boo

extractor = read_zarr(folder)
else:
# the is spikeinterface<=0.94.0
# a folder came with 'cached.json'
# For backward compatibility (v<=0.94) we check for the cached.json/pkl/pickle files
# In later versions (v>0.94) we use the si_folder.json file
for dump_ext in ("json", "pkl", "pickle"):
f = folder / f"cached.{dump_ext}"
if f.is_file():
file = f

# spikeinterface>=0.95.0
f = folder / f"si_folder.json"
if f.is_file():
file = f

if file is None:
raise ValueError(f"This folder is not a cached folder {file_path}")
raise ValueError(error_msg)
extractor = BaseExtractor.load(file, base_folder=folder)

else:
error_msg = (
f"{file_path} is not a file or a folder. It should point to either a json, pickle file or a "
"folder that is the result of extractor.save(...)"
)
raise ValueError(error_msg)
else:
# remote case - zarr
Expand Down

0 comments on commit c4406ca

Please sign in to comment.