# HG changeset patch
# User Ashwin Vishnu <avmo@kth.se>
# Date 1543947426 -3600
#      Tue Dec 04 19:17:06 2018 +0100
# Node ID b1cb84d5e130b6e55344006bd9193f0606e0a697
# Parent  d284a50b6f7005c69e23692b7a599f95c1fe8b48
Help tracing corrupted lines in spatial_means.json

diff --git a/fluidsim/base/output/spatial_means.py b/fluidsim/base/output/spatial_means.py
--- a/fluidsim/base/output/spatial_means.py
+++ b/fluidsim/base/output/spatial_means.py
@@ -191,9 +191,19 @@
 
         try:
             df = pd.read_json(self.path_file, orient="records", lines=True)
+            return df
         except ValueError:
-            raise ValueError(f"Error reading spatial means file {self.path_file}")
-        return df
+            with open(self.path_file) as fp:
+                for line_nb, line in enumerate(fp):
+                    line_nb += 1
+                    try:
+                        json.loads(line)
+                    except json.JSONDecodeError:
+                        break
+
+            raise IOError(
+                f"Error reading spatial means file {self.path_file} in\n\tline"
+                f"number {line_nb}:\n\t{line}")
 
     def load_dataset(self, dims=("t",)):
         df = self.load()