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 @@ -77,12 +77,7 @@ debug.formatters.a = (v?: Multiaddr): string => {
7777 return v == null ? 'undefined' : v . toString ( )
7878}
7979
80- // Add a formatter for stringifying Errors
81- debug . formatters . e = ( v ?: Error ) : string => {
82- if ( v == null ) {
83- return 'undefined'
84- }
85-
80+ function formatError ( v : Error ) : string {
8681 const message = notEmpty ( v . message )
8782 const stack = notEmpty ( v . stack )
8883
@@ -108,6 +103,35 @@ debug.formatters.e = (v?: Error): string => {
108103 return v . toString ( )
109104}
110105
106+ function isAggregateError ( err ?: any ) : err is AggregateError {
107+ return err ?. name === 'AggregateError'
108+ }
109+
110+ // Add a formatter for stringifying Errors
111+ debug . formatters . e = ( v ?: Error ) : string => {
112+ if ( v == null ) {
113+ return 'undefined'
114+ }
115+
116+ if ( isAggregateError ( v ) ) {
117+ const indent = ' '
118+
119+ let output = formatError ( v )
120+
121+ if ( v . errors . length > 0 ) {
122+ output += `\n${ indent } ${
123+ v . errors . map ( err => ` ${ formatError ( err ) . split ( '\n' ) . join ( `\n${ indent } ` ) } ` ) . join ( `\n${ indent } ` )
124+ } `
125+ } else {
126+ output += `\n${ indent } [Error list was empty]`
127+ }
128+
129+ return output . trim ( )
130+ }
131+
132+ return formatError ( v )
133+ }
134+
111135export type { Logger , ComponentLogger }
112136
113137function createDisabledLogger ( namespace : string ) : debug . Debugger {
You can’t perform that action at this time.
0 commit comments