From 4a0ae20570fae30a0832d64ca4c2109cd0b9da65 Mon Sep 17 00:00:00 2001
From: payno <henri.payno@esrf.fr>
Date: Wed, 8 Jan 2025 14:57:56 +0100
Subject: [PATCH] fluoscan: improve error messages

---
 tomoscan/esrf/scan/fluoscan.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tomoscan/esrf/scan/fluoscan.py b/tomoscan/esrf/scan/fluoscan.py
index 77e2415a..90cb6d23 100644
--- a/tomoscan/esrf/scan/fluoscan.py
+++ b/tomoscan/esrf/scan/fluoscan.py
@@ -116,6 +116,8 @@ class FluoTomoScanBase:
             raise RuntimeError("Detectors not initialized")
 
     def get_metadata_from_h5_file(self):
+        if len(self.detected_folders) == 0:
+            raise ValueError("No detector found, unable to load metadata")
         h5_path = os.path.join(self.scan, self.detected_folders[0])
         h5_files = glob.glob1(h5_path, "*.h5")
         if len(h5_files) > 1:
@@ -145,6 +147,8 @@ class FluoTomoScanBase:
                     )
 
     def detect_detectors(self):
+        if len(self.detected_folders) == 0:
+            raise ValueError("No detector found, unable to detect detectors")
         proj_1_dir = os.path.join(self.scan, "fluofit", self.detected_folders[0])
         detected_detectors = []
         file_names = glob.glob1(proj_1_dir, "IMG_*area_density_ngmm2.tif")
@@ -155,6 +159,8 @@ class FluoTomoScanBase:
         return detected_detectors
 
     def detect_elements(self):
+        if len(self.detected_folders) == 0:
+            raise ValueError("No detector found, unable to detect elements")
         proj_1_dir = os.path.join(self.scan, "fluofit", self.detected_folders[0])
         detector = self.detectors[0]
         file_names = glob.glob1(proj_1_dir, f"IMG_{detector}*area_density_ngmm2.tif")
-- 
GitLab