From d0f6fbf84cbdd24396a8f58255d080cde438ec7f Mon Sep 17 00:00:00 2001
From: Chris Smith <csmith55@utk.edu>
Date: Thu, 29 Sep 2016 09:02:34 -0400
Subject: [PATCH] Updated error handling in ioHDF.repack Works in Spyder and
 allows catching of repack error

---
 pycroscopy/io/io_hdf5.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/pycroscopy/io/io_hdf5.py b/pycroscopy/io/io_hdf5.py
index 0411bb3f..35ca1ee1 100644
--- a/pycroscopy/io/io_hdf5.py
+++ b/pycroscopy/io/io_hdf5.py
@@ -85,22 +85,27 @@ class ioHDF5(object):
         '''
         try:
             repack_line = 'h5repack '+self.path+' '+tmpfile
-            subprocess.call(repack_line, shell=True)
+            subprocess.check_output(repack_line,
+                                    stderr=subprocess.STDOUT,
+                                    shell=True)
             sleep(2)
-        except:
+        except subprocess.CalledProcessError as err:
             print('Could not repack hdf5 file')
-            raise StandardError(sys.stderr)
+            raise Exception(err.output)
 
         '''
         Delete the original file and move the temporary file to the originals path
         '''
+# TODO Find way to get the real OS error that works in and out of Spyder
         try:
             os.remove(self.path)
             os.rename(tmpfile, self.path)
         except:
             print('Could not copy repacked file to original path.')
-            raise StandardError(os.error)
-        
+            print('The original file is located {}'.format(self.path))
+            print('The repacked file is located {}'.format(tmpfile))
+            raise
+
         '''
         Open the repacked file
         '''
-- 
GitLab