@@ -203,6 +203,7 @@ const prefixString = ({ path, url, str }) => {
203
203
} ;
204
204
205
205
const processResults = ( { data, errors } ) => {
206
+ const err = { } ;
206
207
if ( errors . length > 0 ) {
207
208
const error = errors . reduce (
208
209
( acc , { path, url, errors } ) => {
@@ -227,46 +228,46 @@ const processResults = ({ data, errors }) => {
227
228
details : '' ,
228
229
} ,
229
230
) ;
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 ;
264
233
}
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
+ } ;
265
265
} ;
266
266
267
267
module . exports = {
268
268
onPostBuild : async ( { constants, utils, inputs } = { } ) => {
269
269
const { failBuild, show } = getUtils ( { utils } ) ;
270
+ let errorMetadata = [ ] ;
270
271
271
272
try {
272
273
const { audits } = getConfiguration ( {
@@ -302,35 +303,40 @@ module.exports = {
302
303
303
304
if ( Array . isArray ( errors ) && errors . length > 0 ) {
304
305
allErrors . push ( { path, url, errors } ) ;
305
- } else {
306
- data . push ( {
307
- path,
308
- url,
309
- summary,
310
- shortSummary,
311
- details,
312
- report,
313
- } ) ;
314
306
}
307
+ data . push ( {
308
+ path,
309
+ url,
310
+ summary,
311
+ shortSummary,
312
+ details,
313
+ report,
314
+ } ) ;
315
315
}
316
316
317
317
const { error, summary, extraData } = processResults ( {
318
318
data,
319
319
errors : allErrors ,
320
320
show,
321
321
} ) ;
322
+ errorMetadata . push ( ...extraData ) ;
322
323
323
- if ( error ) {
324
+ if ( error && Object . keys ( error ) . length !== 0 ) {
324
325
throw error ;
325
326
}
326
327
327
328
show ( { summary, extraData } ) ;
328
329
} catch ( error ) {
329
330
if ( error . details ) {
330
331
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
+ } ) ;
332
335
} else {
333
- failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ` , { error } ) ;
336
+ failBuild ( `${ chalk . red ( 'Failed with error:\n' ) } ` , {
337
+ error,
338
+ errorMetadata,
339
+ } ) ;
334
340
}
335
341
}
336
342
} ,
0 commit comments