Use exceptions for error handling
[rarslave2.git] / RarslaveDetector.py
index 73a442b..dfb2768 100644 (file)
@@ -82,6 +82,7 @@ class RarslaveDetector (object):
                   the class is valid."""
 
                detected = False
+               success = False
 
                for (detector, classname) in self.TYPES:
                        if detector (self.name_matched_files, self.prot_matched_files):
@@ -93,15 +94,18 @@ class RarslaveDetector (object):
                                logging.debug ('Detected type: %s' % p2set)
 
                                # Try to have rarslave do it's thing
-                               ret = p2set.runAll ()
+                               try:
+                                       # Have rarslave do it's thing
+                                       p2set.runAll ()
 
-                               # If something already worked, there is no need to continue,
-                               # since we've already finished!
-                               if ret == rsutil.common.SUCCESS:
+                                       # It succeeded, exit the loop early
+                                       success = True
                                        break
-                               else:
-                                       logging.error ('Detected type (%s) failed for: %s' % (p2set,
-                                                       self.p2file))
+                               except (OSError, RuntimeError):
+                                       logging.error('Detected type (%s) failed for: %s' % (p2set, self.p2file))
+                               except:
+                                       logging.error('Unknown exception occurred')
+                                       raise
 
                # Make sure we detected at least one valid type
                if not detected:
@@ -109,13 +113,10 @@ class RarslaveDetector (object):
                        logging.debug ('The following information will help in writing a detector:')
                        logging.debug ('name_matches: %s' % self.name_matched_files)
                        logging.debug ('prot_matches: %s' % self.prot_matched_files)
-                       return -rsutil.common.EDETECT
 
                # Make sure that something worked
-               if ret != rsutil.common.SUCCESS:
-                       logging.critical ('All types failed for: %s' % self.p2file)
-
-               return ret
+               if success == False:
+                       logging.critical('All types failed for: %s' % self.p2file)
 
 def main ():
        pass