include exception data in error stream output

This commit is contained in:
Michael Stephens 2010-06-30 14:27:57 -04:00
parent 54a99d4d05
commit e201df8eda
3 changed files with 10 additions and 7 deletions

View File

@ -34,9 +34,10 @@ class Recipe(object):
return filters return filters
def reject_record(self, record, message): def reject_record(self, record, exception):
if self.error_stream: if self.error_stream:
self.error_stream.run([record]) self.error_stream.run([{'record': record,
'exception': repr(exception)}])
def run(self, source): def run(self, source):
# load filters # load filters

View File

@ -30,10 +30,10 @@ class Filter(object):
raise NotImplementedError('process_record not defined in ' + raise NotImplementedError('process_record not defined in ' +
self.__class__.__name__) self.__class__.__name__)
def reject_record(self, record, message): def reject_record(self, record, exception):
recipe = getattr(self, '_recipe') recipe = getattr(self, '_recipe')
if recipe: if recipe:
recipe.reject_record(record, message) recipe.reject_record(record, exception)
def attach(self, source, recipe=None): def attach(self, source, recipe=None):
self._recipe = recipe self._recipe = recipe
@ -43,7 +43,7 @@ class Filter(object):
if result is not None: if result is not None:
yield result yield result
except Exception as e: except Exception as e:
self.reject_record(record, unicode(e)) self.reject_record(record, e)
class YieldFilter(Filter): class YieldFilter(Filter):
@ -61,7 +61,7 @@ class YieldFilter(Filter):
for result in self.process_record(record): for result in self.process_record(record):
yield result yield result
except Exception as e: except Exception as e:
self.reject_record(record, unicode(e)) self.reject_record(record, e)
class FieldFilter(Filter): class FieldFilter(Filter):

View File

@ -23,7 +23,9 @@ class RecipeTestCase(unittest.TestCase):
saver = Saver() saver = Saver()
recipe = Recipe(Raiser(), error_stream=saver) recipe = Recipe(Raiser(), error_stream=saver)
recipe.run([{'a': 1}, {'b': 2}]) recipe.run([{'a': 1}, {'b': 2}])
self.assertEqual(saver.saved, [{'a': 1}, {'b': 2}])
self.assertEqual(saver.saved[0]['record'], {'a': 1})
self.assertEqual(saver.saved[1]['record'], {'b': 2})
if __name__ == '__main__': if __name__ == '__main__':