Mercurial > piecrust2
diff piecrust/processing/base.py @ 221:f82262f59600
bake: Fix processing record bugs and error logging for external processes.
Fix problems with processing records not being collapsed correctly.
Make it possible to capture external processes' `stderr` output.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 03 Feb 2015 08:21:43 -0800 |
parents | a47580a0955b |
children | c2ca72fb7f0b |
line wrap: on
line diff
--- a/piecrust/processing/base.py Tue Feb 03 08:20:30 2015 -0800 +++ b/piecrust/processing/base.py Tue Feb 03 08:21:43 2015 -0800 @@ -9,7 +9,8 @@ from piecrust.chefutil import format_timed from piecrust.processing.records import ( ProcessorPipelineRecordEntry, TransitionalProcessorPipelineRecord, - FLAG_PROCESSED, FLAG_OVERRIDEN, FLAG_BYPASSED_STRUCTURED_PROCESSING) + FLAG_PREPARED, FLAG_PROCESSED, FLAG_OVERRIDEN, + FLAG_BYPASSED_STRUCTURED_PROCESSING) from piecrust.processing.tree import ( ProcessingTreeBuilder, ProcessingTreeRunner, ProcessingTreeError, ProcessorError, @@ -20,6 +21,9 @@ logger = logging.getLogger(__name__) +re_ansicolors = re.compile('\033\\[\d+m') + + PRIORITY_FIRST = -1 PRIORITY_NORMAL = 0 PRIORITY_LAST = 1 @@ -105,6 +109,14 @@ raise NotImplementedError() +class ExternalProcessException(Exception): + def __init__(self, stderr_data): + self.stderr_data = stderr_data + + def __str__(self): + return self.stderr_data + + class ProcessingContext(object): def __init__(self, base_dir, mount_info, job_queue, record=None): self.base_dir = base_dir @@ -360,9 +372,10 @@ try: builder = ProcessingTreeBuilder(processors) tree_root = builder.build(rel_path) + record_entry.flags |= FLAG_PREPARED except ProcessingTreeError as ex: msg = str(ex) - logger.error("Error processing %s: %s" % (rel_path, msg)) + logger.error("Error preparing %s:\n%s" % (rel_path, msg)) while ex: record_entry.errors.append(str(ex)) ex = ex.__cause__ @@ -396,9 +409,10 @@ msg = str(ex) if isinstance(ex, ProcessorError): msg = str(ex.__cause__) - logger.error("Error processing %s: %s" % (rel_path, msg)) + logger.error("Error processing %s:\n%s" % (rel_path, msg)) while ex: - record_entry.errors.append(str(ex)) + msg = re_ansicolors.sub('', str(ex)) + record_entry.errors.append(msg) ex = ex.__cause__ return False