66
77import {
88 createStackTraceForConsoleMessage ,
9- createStackTrace ,
109 type TargetUniverse ,
10+ SymbolizedError ,
1111} from '../DevtoolsUtils.js' ;
12- import type { UncaughtError } from '../PageCollector.js' ;
12+ import { UncaughtError } from '../PageCollector.js' ;
1313import type * as DevTools from '../third_party/index.js' ;
1414import type { ConsoleMessage } from '../third_party/index.js' ;
1515
@@ -21,13 +21,13 @@ export interface ConsoleFormatterOptions {
2121}
2222
2323export class ConsoleFormatter {
24- #msg: ConsoleMessage | Error | UncaughtError ;
24+ #msg: ConsoleMessage | Error | SymbolizedError ;
2525 #resolvedArgs: unknown [ ] = [ ] ;
2626 #resolvedStackTrace?: DevTools . DevTools . StackTrace . StackTrace . StackTrace ;
2727 #id?: number ;
2828
2929 private constructor (
30- msg : ConsoleMessage | Error | UncaughtError ,
30+ msg : ConsoleMessage | Error | SymbolizedError ,
3131 options ?: ConsoleFormatterOptions ,
3232 ) {
3333 this . #msg = msg ;
@@ -39,6 +39,19 @@ export class ConsoleFormatter {
3939 msg : ConsoleMessage | Error | UncaughtError ,
4040 options ?: ConsoleFormatterOptions ,
4141 ) : Promise < ConsoleFormatter > {
42+ if ( msg instanceof UncaughtError ) {
43+ return new ConsoleFormatter (
44+ await SymbolizedError . fromDetails ( {
45+ devTools : options ?. devTools ,
46+ details : msg . details ,
47+ targetId : msg . targetId ,
48+ includeStackAndCause : options ?. fetchDetailedData ,
49+ resolvedStackTraceForTesting : options ?. resolvedStackTraceForTesting ,
50+ } ) ,
51+ options ,
52+ ) ;
53+ }
54+
4255 const formatter = new ConsoleFormatter ( msg , options ) ;
4356 if ( options ?. fetchDetailedData ) {
4457 await formatter . #loadDetailedData( options ?. devTools ) ;
@@ -47,7 +60,7 @@ export class ConsoleFormatter {
4760 }
4861
4962 #isConsoleMessage(
50- msg : ConsoleMessage | Error | UncaughtError ,
63+ msg : ConsoleMessage | Error | SymbolizedError ,
5164 ) : msg is ConsoleMessage {
5265 // No `instanceof` as tests mock `ConsoleMessage`.
5366 return 'args' in msg && typeof msg . args === 'function' ;
@@ -77,12 +90,6 @@ export class ConsoleFormatter {
7790 devTools ,
7891 this . #msg,
7992 ) ;
80- } else if ( this . #msg. stackTrace ) {
81- this . #resolvedStackTrace = await createStackTrace (
82- devTools ,
83- this . #msg. stackTrace ,
84- this . #msg. targetId ,
85- ) ;
8693 }
8794 } catch {
8895 // ignore
@@ -105,7 +112,11 @@ export class ConsoleFormatter {
105112 this . #id !== undefined ? `ID: ${ this . #id} ` : '' ,
106113 `Message: ${ this . #getType( ) } > ${ this . #getText( ) } ` ,
107114 this . #formatArgs( ) ,
108- this . #formatStackTrace( this . #resolvedStackTrace) ,
115+ this . #formatStackTrace(
116+ this . #msg instanceof SymbolizedError
117+ ? this . #msg. stackTrace
118+ : this . #resolvedStackTrace,
119+ ) ,
109120 ] . filter ( line => ! ! line ) ;
110121 return result . join ( '\n' ) ;
111122 }
0 commit comments