include exception data in error stream output
This commit is contained in:
parent
54a99d4d05
commit
e201df8eda
@ -34,9 +34,10 @@ class Recipe(object):
|
||||
|
||||
return filters
|
||||
|
||||
def reject_record(self, record, message):
|
||||
def reject_record(self, record, exception):
|
||||
if self.error_stream:
|
||||
self.error_stream.run([record])
|
||||
self.error_stream.run([{'record': record,
|
||||
'exception': repr(exception)}])
|
||||
|
||||
def run(self, source):
|
||||
# load filters
|
||||
|
@ -30,10 +30,10 @@ class Filter(object):
|
||||
raise NotImplementedError('process_record not defined in ' +
|
||||
self.__class__.__name__)
|
||||
|
||||
def reject_record(self, record, message):
|
||||
def reject_record(self, record, exception):
|
||||
recipe = getattr(self, '_recipe')
|
||||
if recipe:
|
||||
recipe.reject_record(record, message)
|
||||
recipe.reject_record(record, exception)
|
||||
|
||||
def attach(self, source, recipe=None):
|
||||
self._recipe = recipe
|
||||
@ -43,7 +43,7 @@ class Filter(object):
|
||||
if result is not None:
|
||||
yield result
|
||||
except Exception as e:
|
||||
self.reject_record(record, unicode(e))
|
||||
self.reject_record(record, e)
|
||||
|
||||
|
||||
class YieldFilter(Filter):
|
||||
@ -61,7 +61,7 @@ class YieldFilter(Filter):
|
||||
for result in self.process_record(record):
|
||||
yield result
|
||||
except Exception as e:
|
||||
self.reject_record(record, unicode(e))
|
||||
self.reject_record(record, e)
|
||||
|
||||
|
||||
class FieldFilter(Filter):
|
||||
|
@ -23,7 +23,9 @@ class RecipeTestCase(unittest.TestCase):
|
||||
saver = Saver()
|
||||
recipe = Recipe(Raiser(), error_stream=saver)
|
||||
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__':
|
||||
|
Loading…
Reference in New Issue
Block a user