Skip to content

Commit 558ce16

Browse files
authored
Updated error messages for incorrectly formatted zip files (#74)
1 parent 22f005c commit 558ce16

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/datalab_app_plugin_insitu/apps/uvvis/blocks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ def generate_insitu_uvvis_plot(self, file_path: Path | None = None, link_plots:
191191

192192
required_folders = ["uvvis_folder_name", "echem_folder_name", "uvvis_reference_folder_name"]
193193

194+
# If there is an incorrect number of folders, raise an error
195+
if len(folders) < len(required_folders):
196+
raise RuntimeError(
197+
f"Incorrect zip format detected: found {len(folders)} folders in the provided zip file. Expected a zip file with {len(required_folders)} folders: a UV-Vis folder (containing sample scans), an electrochemical folder, and a UV-Vis reference folder (containing the background scan). For more information see https://datalab-app-plugin-insitu.readthedocs.io/en/latest/"
198+
)
199+
194200
for folder in required_folders:
195201
if not self.data.get(folder):
196202
return

src/datalab_app_plugin_insitu/apps/xrd/blocks.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ def process_and_store_data(self, file_path: str | Path):
8585
Process all in situ XRD, log and (optional) electrochemical data and store results.
8686
This method is a wrapper for processing both XRD and electrochemical data and the log data.
8787
"""
88-
xrd_folder_name = Path(self.data.get("xrd_folder_name"))
88+
xrd_folder_name = self.data.get("xrd_folder_name")
8989
if not xrd_folder_name:
9090
raise ValueError("XRD folder name is required")
91+
else:
92+
xrd_folder_name = Path(xrd_folder_name)
9193

92-
time_series_folder_name = Path(self.data.get("time_series_folder_name"))
94+
time_series_folder_name = self.data.get("time_series_folder_name")
9395
if not time_series_folder_name:
9496
raise ValueError("Log or echem folder name is required")
97+
else:
98+
time_series_folder_name = Path(time_series_folder_name)
9599

96100
start_exp = int(self.data.get("start_exp", self.defaults["start_exp"]))
97101
exclude_exp = self.data.get("exclude_exp", self.defaults["exclude_exp"])
@@ -213,8 +217,18 @@ def generate_insitu_xrd_plot(self, file_path: Path | None = None, link_plots: bo
213217

214218
if self.data.get("time_series_source") == "log":
215219
required_folders = ["xrd_folder_name", "time_series_folder_name"]
220+
# If there is an incorrect number of folders, raise an error
221+
if len(folders) < len(required_folders):
222+
raise RuntimeError(
223+
f"Incorrect zip format detected: found {len(folders)} folders in the provided zip file. Expected a zip file with {len(required_folders)} folders: an xrd folder and a log folder. For more information see https://datalab-app-plugin-insitu.readthedocs.io/en/latest/"
224+
)
216225
elif self.data.get("time_series_source") == "echem":
217226
required_folders = ["xrd_folder_name", "time_series_folder_name", "echem_folder_name"]
227+
# If there is an incorrect number of folders, raise an error
228+
if len(folders) < len(required_folders):
229+
raise RuntimeError(
230+
f"Incorrect zip format detected: found {len(folders)} folders in the provided zip file. Expected a zip file with {len(required_folders)} folders: an xrd folder, an echem folder, and a log folder. For more information see https://datalab-app-plugin-insitu.readthedocs.io/en/latest/"
231+
)
218232
else:
219233
raise ValueError(
220234
"time_series_source must be set to either 'log' or 'echem' in the datablock data"

0 commit comments

Comments
 (0)