@@ -203,6 +203,7 @@ const prefixString = ({ path, url, str }) => {
203203} ;
204204
205205const processResults = ( { data, errors } ) => {
206+ const err = { } ;
206207 if ( errors . length > 0 ) {
207208 const error = errors . reduce (
208209 ( acc , { path, url, errors } ) => {
@@ -227,46 +228,46 @@ const processResults = ({ data, errors }) => {
227228 details : '' ,
228229 } ,
229230 ) ;
230- return {
231- error,
232- } ;
233- } else {
234- const reports = [ ] ;
235- return {
236- summary : data
237- . map ( ( { path, url, summary, shortSummary, details, report } ) => {
238- const obj = { report, details } ;
239-
240- if ( summary ) {
241- obj . summary = summary . reduce ( ( acc , item ) => {
242- acc [ item . id ] = Math . round ( item . score * 100 ) ;
243- return acc ;
244- } , { } ) ;
245- }
246-
247- if ( path ) {
248- obj . path = path ;
249- reports . push ( obj ) ;
250- return `Summary for directory '${ chalk . magenta (
251- path ,
252- ) } ': ${ shortSummary } `;
253- }
254- if ( url ) {
255- obj . url = url ;
256- reports . push ( obj ) ;
257- return `Summary for url '${ chalk . magenta ( url ) } ': ${ shortSummary } ` ;
258- }
259- return `${ shortSummary } ` ;
260- } )
261- . join ( '\n' ) ,
262- extraData : reports ,
263- } ;
231+ err . message = error . message ;
232+ err . details = error . details ;
264233 }
234+ const reports = [ ] ;
235+ return {
236+ error : err ,
237+ summary : data
238+ . map ( ( { path, url, summary, shortSummary, details, report } ) => {
239+ const obj = { report, details } ;
240+
241+ if ( summary ) {
242+ obj . summary = summary . reduce ( ( acc , item ) => {
243+ acc [ item . id ] = Math . round ( item . score * 100 ) ;
244+ return acc ;
245+ } , { } ) ;
246+ }
247+
248+ if ( path ) {
249+ obj . path = path ;
250+ reports . push ( obj ) ;
251+ return `Summary for directory '${ chalk . magenta (
252+ path ,
253+ ) } ': ${ shortSummary } `;
254+ }
255+ if ( url ) {
256+ obj . url = url ;
257+ reports . push ( obj ) ;
258+ return `Summary for url '${ chalk . magenta ( url ) } ': ${ shortSummary } ` ;
259+ }
260+ return `${ shortSummary } ` ;
261+ } )
262+ . join ( '\n' ) ,
263+ extraData : reports ,
264+ } ;
265265} ;
266266
267267module . exports = {
268268 onPostBuild : async ( { constants, utils, inputs } = { } ) => {
269269 const { failBuild, show } = getUtils ( { utils } ) ;
270+ let errorMetadata = [ ] ;
270271
271272 try {
272273 const { audits } = getConfiguration ( {
@@ -302,35 +303,40 @@ module.exports = {
302303
303304 if ( Array . isArray ( errors ) && errors . length > 0 ) {
304305 allErrors . push ( { path, url, errors } ) ;
305- } else {
306- data . push ( {
307- path,
308- url,
309- summary,
310- shortSummary,
311- details,
312- report,
313- } ) ;
314306 }
307+ data . push ( {
308+ path,
309+ url,
310+ summary,
311+ shortSummary,
312+ details,
313+ report,
314+ } ) ;
315315 }
316316
317317 const { error, summary, extraData } = processResults ( {
318318 data,
319319 errors : allErrors ,
320320 show,
321321 } ) ;
322+ errorMetadata . push ( ...extraData ) ;
322323
323- if ( error ) {
324+ if ( error && Object . keys ( error ) . length !== 0 ) {
324325 throw error ;
325326 }
326327
327328 show ( { summary, extraData } ) ;
328329 } catch ( error ) {
329330 if ( error . details ) {
330331 console . error ( error . details ) ;
331- failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ${ error . message } ` ) ;
332+ failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ${ error . message } ` , {
333+ errorMetadata,
334+ } ) ;
332335 } else {
333- failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ` , { error } ) ;
336+ failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ` , {
337+ error,
338+ errorMetadata,
339+ } ) ;
334340 }
335341 }
336342 } ,
0 commit comments