@@ -15,6 +15,7 @@ export interface ConsoleMessageData {
1515 count ?: number ;
1616 description ?: string ;
1717 args ?: string [ ] ;
18+ stackTrace ?: DevTools . StackTrace . StackTrace . StackTrace ;
1819}
1920
2021// The short format for a console message, based on a previous format.
@@ -46,6 +47,7 @@ export function formatConsoleEventVerbose(
4647 `ID: ${ msg . consoleMessageStableId } ` ,
4748 `Message: ${ msg . type } > ${ aggregatedIssue ? formatIssue ( aggregatedIssue , msg . description , context ) : msg . message } ` ,
4849 aggregatedIssue ? undefined : formatArgs ( msg ) ,
50+ formatStackTrace ( msg . stackTrace ) ,
4951 ] . filter ( line => ! ! line ) ;
5052 return result . join ( '\n' ) ;
5153}
@@ -163,3 +165,42 @@ export function formatIssue(
163165 if ( result . length === 0 ) return 'No affected resources found' ;
164166 return result . join ( '\n' ) ;
165167}
168+
169+ function formatStackTrace (
170+ stackTrace : DevTools . StackTrace . StackTrace . StackTrace | undefined ,
171+ ) : string {
172+ if ( ! stackTrace ) {
173+ return '' ;
174+ }
175+
176+ return [
177+ '### Stack trace' ,
178+ formatFragment ( stackTrace . syncFragment ) ,
179+ ...stackTrace . asyncFragments . map ( formatAsyncFragment ) ,
180+ ] . join ( '\n' ) ;
181+ }
182+
183+ function formatFragment (
184+ fragment : DevTools . StackTrace . StackTrace . Fragment ,
185+ ) : string {
186+ return fragment . frames . map ( formatFrame ) . join ( '\n' ) ;
187+ }
188+
189+ function formatAsyncFragment (
190+ fragment : DevTools . StackTrace . StackTrace . AsyncFragment ,
191+ ) : string {
192+ const separatorLineLength = 40 ;
193+ const prefix = `--- ${ fragment . description || 'async' } ` ;
194+ const separator = prefix + '-' . repeat ( separatorLineLength - prefix . length ) ;
195+ return separator + '\n' + formatFragment ( fragment ) ;
196+ }
197+
198+ function formatFrame ( frame : DevTools . StackTrace . StackTrace . Frame ) : string {
199+ let result = `at ${ frame . name ?? '<anonymous>' } ` ;
200+ if ( frame . uiSourceCode ) {
201+ result += ` (${ frame . uiSourceCode . displayName ( ) } :${ frame . line } :${ frame . column } )` ;
202+ } else if ( frame . url ) {
203+ result += ` (${ frame . url } :${ frame . line } :${ frame . column } )` ;
204+ }
205+ return result ;
206+ }
0 commit comments