Skip to content

Commit

Permalink
wip: improve error messages in log
Browse files Browse the repository at this point in the history
  • Loading branch information
maurov committed Sep 15, 2023
1 parent f8412c9 commit ef20eed
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions larch/io/specfile_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __init__(self, fname=None, logger=None, urls_fmt="silx", verbose=False):
if logger is None:
from larch.utils.logging import getLogger

_logger_name = "larch.io.specfile_reader.DataSourceSpecH5"
_logger_name = "DataSourceSpecH5"
self._logger = getLogger(_logger_name, level="WARNING")
else:
self._logger = logger
Expand All @@ -264,6 +264,7 @@ def __init__(self, fname=None, logger=None, urls_fmt="silx", verbose=False):
self._logger.setLevel("DEBUG")

self._fname = fname
self._fn = self._fname
self._sourcefile = None
self._sourcefile_type = None
self._scans = None
Expand Down Expand Up @@ -328,6 +329,7 @@ def _init_source_file(self):
try:
if h5py.is_hdf5(self._fname):
self._sourcefile = silx_h5py_file(self._fname, mode="r")
self._logger.debug("HDF5 open with silx.io.h5py_utils")
else:
self._sourcefile = silx_open(self._fname)
for ft in self._file_types:
Expand All @@ -351,14 +353,19 @@ def _init_source_file(self):
_errmsg = f"cannot open {self._fname}"
self._logger.error(_errmsg)
raise OSError(_errmsg)
try:
self._fn = self._fname.split(os.sep)[-1]
except Exception:
self._logger.debug(f"cannot split {self._fname}")
pass

def open(self, mode="r"):
"""Open the source file object with h5py in given mode"""
try:
if h5py.is_hdf5(self._fname):
self._sourcefile = silx_h5py_file(self._fname, mode)
else:
_errmsg = f"{self._fname} is not and HDF5 file"
_errmsg = f"{self._fname} is not HDF5 file"
self._logger.error(_errmsg)
raise ValueError(_errmsg)
except OSError:
Expand Down Expand Up @@ -495,9 +502,9 @@ def _list_from_url(self, url_str):
try:
return [i for i in self.get_scangroup()[url_str].keys()]
except Exception:
_errmsg = f"'{url_str}' not found -> use 'set_scan' method first"
_errmsg = f"[{self._fn}//{self._scan_n}] '{url_str}' not found"
self._logger.error(_errmsg)
raise ValueError(_errmsg)
#raise ValueError(_errmsg)

# ================== #
#: READ DATA METHODS
Expand Down Expand Up @@ -738,7 +745,7 @@ def get_array(self, cnt=0):
sel_cnt = f"{self._cnts_url}/{cnt}"
return copy.deepcopy(sg[sel_cnt][()])
else:
errmsg = f"'{cnt}' not found in available counters: {cnts}"
errmsg = f"[{self._fn}//{self._scan_n}] '{cnt}' not found in available counters"
self._logger.error(errmsg)
raise ValueError(errmsg)

Expand All @@ -763,7 +770,7 @@ def get_motor_position(self, mot):
sel_mot = f"{self._mots_url}/{mot}"
return copy.deepcopy(sg[sel_mot][()])
else:
self._logger.error(f"'{mot}' not found in available motors: {mots}")
self._logger.error(f"[{self._fn}//{self._scan_n}] '{mot}' not found in available motors")
return None

def get_scan(self, scan=None, datatype=None):
Expand Down

0 comments on commit ef20eed

Please sign in to comment.