@@ -23,6 +23,8 @@ export interface ConsoleFormatterOptions {
2323}
2424
2525export class ConsoleFormatter {
26+ static readonly #STACK_TRACE_MAX_LINES = 50 ;
27+
2628 readonly #id: number ;
2729 readonly #type: string ;
2830 readonly #text: string ;
@@ -134,7 +136,6 @@ export class ConsoleFormatter {
134136 this . #formatArgs( ) ,
135137 this . #formatStackTrace( this . #stack, this . #cause, {
136138 includeHeading : true ,
137- includeNote : true ,
138139 } ) ,
139140 ] . filter ( line => ! ! line ) ;
140141 return result . join ( '\n' ) ;
@@ -158,7 +159,6 @@ export class ConsoleFormatter {
158159 arg . message ,
159160 this . #formatStackTrace( arg . stackTrace , arg . cause , {
160161 includeHeading : false ,
161- includeNote : true ,
162162 } ) ,
163163 ]
164164 . filter ( line => ! ! line )
@@ -186,38 +186,59 @@ export class ConsoleFormatter {
186186 #formatStackTrace(
187187 stackTrace : DevTools . DevTools . StackTrace . StackTrace . StackTrace | undefined ,
188188 cause : SymbolizedError | undefined ,
189- opts : { includeHeading : boolean ; includeNote : boolean } ,
189+ opts : { includeHeading : boolean } ,
190190 ) : string {
191191 if ( ! stackTrace ) {
192192 return '' ;
193193 }
194194
195+ const lines = this . #formatStackTraceInner( stackTrace , cause ) ;
196+ const includedLines = lines . slice (
197+ 0 ,
198+ ConsoleFormatter . #STACK_TRACE_MAX_LINES,
199+ ) ;
200+ const reminderCount = lines . length - includedLines . length ;
201+
195202 return [
196203 opts . includeHeading ? '### Stack trace' : '' ,
197- this . #formatFragment( stackTrace . syncFragment ) ,
198- ...stackTrace . asyncFragments . map ( this . #formatAsyncFragment. bind ( this ) ) ,
199- this . #formatCause( cause ) ,
200- opts . includeNote
201- ? 'Note: line and column numbers use 1-based indexing'
202- : '' ,
204+ ...includedLines ,
205+ reminderCount > 0 ? `... and ${ reminderCount } more frames` : '' ,
206+ 'Note: line and column numbers use 1-based indexing' ,
203207 ]
204208 . filter ( line => ! ! line )
205209 . join ( '\n' ) ;
206210 }
207211
212+ #formatStackTraceInner(
213+ stackTrace : DevTools . DevTools . StackTrace . StackTrace . StackTrace | undefined ,
214+ cause : SymbolizedError | undefined ,
215+ ) : string [ ] {
216+ if ( ! stackTrace ) {
217+ return [ ] ;
218+ }
219+
220+ return [
221+ ...this . #formatFragment( stackTrace . syncFragment ) ,
222+ ...stackTrace . asyncFragments
223+ . map ( this . #formatAsyncFragment. bind ( this ) )
224+ . flat ( ) ,
225+ ...this . #formatCause( cause ) ,
226+ ] ;
227+ }
228+
208229 #formatFragment(
209230 fragment : DevTools . DevTools . StackTrace . StackTrace . Fragment ,
210- ) : string {
211- return fragment . frames . map ( this . #formatFrame. bind ( this ) ) . join ( '\n' ) ;
231+ ) : string [ ] {
232+ return fragment . frames . map ( this . #formatFrame. bind ( this ) ) ;
212233 }
213234
214235 #formatAsyncFragment(
215236 fragment : DevTools . DevTools . StackTrace . StackTrace . AsyncFragment ,
216- ) : string {
237+ ) : string [ ] {
217238 const separatorLineLength = 40 ;
218239 const prefix = `--- ${ fragment . description || 'async' } ` ;
219240 const separator = prefix + '-' . repeat ( separatorLineLength - prefix . length ) ;
220- return separator + '\n' + this . #formatFragment( fragment ) ;
241+ return [ separator , ... this . #formatFragment( fragment ) ] ;
221242 }
222243
223244 #formatFrame( frame : DevTools . DevTools . StackTrace . StackTrace . Frame ) : string {
@@ -231,20 +252,15 @@ export class ConsoleFormatter {
231252 return result ;
232253 }
233254
234- #formatCause( cause : SymbolizedError | undefined ) : string {
255+ #formatCause( cause : SymbolizedError | undefined ) : string [ ] {
235256 if ( ! cause ) {
236- return '' ;
257+ return [ ] ;
237258 }
238259
239260 return [
240261 `Caused by: ${ cause . message } ` ,
241- this . #formatStackTrace( cause . stackTrace , cause . cause , {
242- includeHeading : false ,
243- includeNote : false ,
244- } ) ,
245- ]
246- . filter ( line => ! ! line )
247- . join ( '\n' ) ;
262+ ...this . #formatStackTraceInner( cause . stackTrace , cause . cause ) ,
263+ ] ;
248264 }
249265
250266 toJSON ( ) : object {
0 commit comments