diff piecrust/processing/tree.py @ 215:a47580a0955b

bake: Better error handling for the processing pipeline. Pipeline jobs now keep track of whether they've seen any errors. This is aggregated into an overall "success" flag for the processing record. Also, jobs keep going as long as there's no critical (i.e. internal) failure happening. Errors raised by processors are also better tracked: the actual processor that failed, along with the input file, are tracks in the processing record. The `bake` command returns a failure exit code if processing saw any error.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 31 Jan 2015 17:08:02 -0800
parents 308d5180bf81
children c4b3a7fd2f87
line wrap: on
line diff
--- a/piecrust/processing/tree.py	Sat Jan 31 16:28:16 2015 -0800
+++ b/piecrust/processing/tree.py	Sat Jan 31 17:08:02 2015 -0800
@@ -24,6 +24,16 @@
     pass
 
 
+class ProcessorError(ProcessingTreeError):
+    def __init__(self, proc_name, in_path, *args):
+        super(ProcessorError, self).__init__(*args)
+        self.proc_name = proc_name
+        self.in_path = in_path
+
+    def __str__(self):
+        return "Processor %s failed on: %s" % (self.proc_name, self.in_path)
+
+
 class ProcessingTreeNode(object):
     def __init__(self, path, available_procs, level=0):
         self.path = path
@@ -154,8 +164,7 @@
                             colored=False))
                 return True
             except Exception as e:
-                raise ProcessingTreeError("Error processing: %s" %
-                        node.path) from e
+                raise ProcessorError(proc.PROCESSOR_NAME, full_path) from e
 
         # All outputs of a node must go to the same directory, so we can get
         # the output directory off of the first output.
@@ -183,7 +192,7 @@
                 print_node(node, "-> %s [clean]" % out_dir)
                 return False
         except Exception as e:
-            raise Exception("Error processing: %s" % node.path) from e
+            raise ProcessorError(proc.PROCESSOR_NAME, full_path) from e
 
     def _computeNodeState(self, node):
         if node.state != STATE_UNKNOWN: