diff piecrust/commands/builtin/baking.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 e725af1d48fb
children 1f4c3dae1fe8
line wrap: on
line diff
--- a/piecrust/commands/builtin/baking.py	Sat Jan 31 16:28:16 2015 -0800
+++ b/piecrust/commands/builtin/baking.py	Sat Jan 31 17:08:02 2015 -0800
@@ -40,19 +40,20 @@
         out_dir = (ctx.args.output or
                    os.path.join(ctx.app.root_dir, '_counter'))
 
+        success = True
         start_time = time.clock()
         try:
             # Bake the site sources.
-            self._bakeSources(ctx, out_dir)
+            success = success & self._bakeSources(ctx, out_dir)
 
             # Bake the assets.
             if not ctx.args.no_assets:
-                self._bakeAssets(ctx, out_dir)
+                success = success & self._bakeAssets(ctx, out_dir)
 
             # All done.
             logger.info('-------------------------')
             logger.info(format_timed(start_time, 'done baking'))
-            return 0
+            return 0 if success else 1
         except Exception as ex:
             if ctx.app.debug:
                 logger.exception(ex)
@@ -65,12 +66,14 @@
                 ctx.app, out_dir,
                 force=ctx.args.force)
         baker.bake()
+        return True
 
     def _bakeAssets(self, ctx, out_dir):
         proc = ProcessorPipeline(
                 ctx.app, out_dir,
                 force=ctx.args.force)
-        proc.run()
+        record = proc.run()
+        return record.success
 
 
 class ShowRecordCommand(ChefCommand):