@@ -236,10 +236,11 @@ function createByline(state, stats) {
236
236
* Info passed around.
237
237
* @param {unknown } cause
238
238
* Cause.
239
- * @returns {Array<string> }
239
+ * @returns {Array<Array<string> | string> }
240
240
* Lines.
241
241
*/
242
242
function createCauseLines ( state , cause ) {
243
+ /** @type {Array<Array<string> | string> } */
243
244
const lines = [ ' ' + state . bold + '[cause]' + state . normalIntensity + ':' ]
244
245
let foundReasonableCause = false
245
246
@@ -250,15 +251,34 @@ function createCauseLines(state, cause) {
250
251
251
252
if ( typeof stackValue === 'string' ) {
252
253
foundReasonableCause = true
254
+ /** @type {Array<Array<string> | string> } */
255
+ let causeLines
256
+
257
+ // Looks like a message.
258
+ if ( 'file' in cause && 'fatal' in cause ) {
259
+ causeLines = createMessageLine (
260
+ state ,
261
+ /** @type {VFileMessage } */ ( cause )
262
+ )
263
+ }
264
+ // Regular error.
265
+ else {
266
+ causeLines = stackValue . split ( eol )
253
267
254
- const stackLines = stackValue . split ( eol )
255
- stackLines [ 0 ] = ' ' + stackLines [ 0 ]
256
-
257
- lines . push ( ...stackLines )
268
+ // Recurse.
269
+ if ( 'cause' in cause && cause . cause ) {
270
+ causeLines . push ( ...createCauseLines ( state , cause . cause ) )
271
+ }
272
+ }
258
273
259
- if ( 'cause' in cause && cause . cause ) {
260
- lines . push ( ...createCauseLines ( state , cause . cause ) )
274
+ const head = causeLines [ 0 ]
275
+ if ( typeof head === 'string' ) {
276
+ causeLines [ 0 ] = ' ' + head
277
+ } else {
278
+ head [ 0 ] = ' ' + head [ 0 ]
261
279
}
280
+
281
+ lines . push ( ...causeLines )
262
282
}
263
283
}
264
284
@@ -345,7 +365,7 @@ function createMessageLine(state, message) {
345
365
let reason = message . stack || message . message
346
366
347
367
const match = eol . exec ( reason )
348
- /** @type {Array<string> } */
368
+ /** @type {Array<Array<string> | string> } */
349
369
let rest = [ ]
350
370
351
371
if ( match ) {
0 commit comments