@@ -14,8 +14,8 @@ var rarity = require('rarity');
1414var util = require ( 'util' ) ;
1515
1616var lib = require ( '../index.js' ) ;
17-
1817var HydrationError = lib . HydrationError ;
18+ var logError = require ( '../utils' ) . logError ;
1919
2020
2121
@@ -52,6 +52,12 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
5252 if ( ! cleaner . called ) {
5353 cleaner . called = true ;
5454 if ( err ) {
55+ var extra = JSON . parse ( JSON . stringify ( task ) ) ;
56+ extra . changes = changes ;
57+ extra . stdout = stdout ;
58+ extra . stderr = stderr ;
59+
60+ logError ( err , extra ) ;
5561 child . reset ( ) ;
5662 }
5763 else {
@@ -170,7 +176,7 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
170176 cb ( null , changes ) ;
171177 } ,
172178 function patchDocument ( changes , cb ) {
173- // Returning null means we won't complete the hdyration , and are waiting for something else.
179+ // Returning null means we won't complete the hydration , and are waiting for something else.
174180 if ( changes === null ) {
175181 logger ( "Skipped task: " + ( ( task . file_path ) ? task . file_path : task . document . id ) ) ;
176182 return cb ( ) ;
@@ -187,8 +193,11 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
187193 }
188194 ] , function handleErrors ( err , changes , res ) {
189195 async . waterfall ( [
190- function logError ( cb ) {
196+ function logErrors ( cb ) {
191197 if ( err ) {
198+ var extra = JSON . parse ( JSON . stringify ( task ) ) ;
199+ extra . changes = changes ;
200+ logError ( err , extra ) ;
192201 errLogger ( "ERR hydrating " + ( ( task . file_path ) ? task . file_path : task . document . id ) , err . toString ( ) ) ;
193202 }
194203
@@ -214,7 +223,11 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
214223 }
215224 }
216225 ] , function ( internalErr ) {
226+ /* istanbul ignore next */
217227 if ( internalErr ) {
228+ var extra = JSON . parse ( JSON . stringify ( task ) ) ;
229+ extra . changes = changes ;
230+ logError ( internalErr , extra ) ;
218231 errLogger ( "INTERNAL ERR" , internalErr ) ;
219232 }
220233 done ( err || internalErr , changes ) ;
0 commit comments