File tree Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -80,12 +80,7 @@ debug.formatters.a = (v?: Multiaddr): string => {
8080 return v == null ? 'undefined' : v . toString ( )
8181}
8282
83- // Add a formatter for stringifying Errors
84- debug . formatters . e = ( v ?: Error ) : string => {
85- if ( v == null ) {
86- return 'undefined'
87- }
88-
83+ function formatError ( v : Error ) : string {
8984 const message = notEmpty ( v . message )
9085 const stack = notEmpty ( v . stack )
9186
@@ -111,6 +106,35 @@ debug.formatters.e = (v?: Error): string => {
111106 return v . toString ( )
112107}
113108
109+ function isAggregateError ( err ?: any ) : err is AggregateError {
110+ return err ?. name === 'AggregateError'
111+ }
112+
113+ // Add a formatter for stringifying Errors
114+ debug . formatters . e = ( v ?: Error ) : string => {
115+ if ( v == null ) {
116+ return 'undefined'
117+ }
118+
119+ if ( isAggregateError ( v ) ) {
120+ const indent = ' '
121+
122+ let output = formatError ( v )
123+
124+ if ( v . errors . length > 0 ) {
125+ output += `\n${ indent } ${
126+ v . errors . map ( err => ` ${ formatError ( err ) . split ( '\n' ) . join ( `\n${ indent } ` ) } ` ) . join ( `\n${ indent } ` )
127+ } `
128+ } else {
129+ output += `\n${ indent } [Error list was empty]`
130+ }
131+
132+ return output . trim ( )
133+ }
134+
135+ return formatError ( v )
136+ }
137+
114138export type { Logger , ComponentLogger }
115139
116140function createDisabledLogger ( namespace : string ) : debug . Debugger {
You can’t perform that action at this time.
0 commit comments