@@ -40,8 +40,10 @@ use anyhow::anyhow;
40
40
use napi:: bindgen_prelude:: { External , Status } ;
41
41
use once_cell:: sync:: Lazy ;
42
42
use owo_colors:: OwoColorize ;
43
+ use terminal_hyperlink:: Hyperlink ;
43
44
use tracing_chrome:: { ChromeLayerBuilder , FlushGuard } ;
44
45
use tracing_subscriber:: { filter, prelude:: * , util:: SubscriberInitExt , Layer } ;
46
+ use turbopack_core:: error:: PrettyPrintError ;
45
47
46
48
static LOG_THROTTLE : Mutex < Option < Instant > > = Mutex :: new ( None ) ;
47
49
static LOG_DIVIDER : & str = "---------------------------" ;
@@ -51,7 +53,7 @@ static PANIC_LOG: Lazy<PathBuf> = Lazy::new(|| {
51
53
path
52
54
} ) ;
53
55
54
- pub fn log_internal_error_and_inform ( err_info : & str ) {
56
+ pub fn log_internal_error_and_inform ( internal_error : & anyhow :: Error ) {
55
57
if cfg ! ( debug_assertions)
56
58
|| env:: var ( "SWC_DEBUG" ) == Ok ( "1" . to_string ( ) )
57
59
|| env:: var ( "CI" ) . is_ok_and ( |v| !v. is_empty ( ) )
@@ -61,7 +63,7 @@ pub fn log_internal_error_and_inform(err_info: &str) {
61
63
eprintln ! (
62
64
"{}: An unexpected Turbopack error occurred:\n {}" ,
63
65
"FATAL" . red( ) . bold( ) ,
64
- err_info
66
+ internal_error . to_string ( )
65
67
) ;
66
68
return ;
67
69
}
@@ -122,8 +124,36 @@ pub fn log_internal_error_and_inform(err_info: &str) {
122
124
. open ( PANIC_LOG . as_path ( ) )
123
125
. unwrap_or_else ( |_| panic ! ( "Failed to open {}" , PANIC_LOG . to_string_lossy( ) ) ) ;
124
126
125
- writeln ! ( log_file, "{}\n {}" , LOG_DIVIDER , err_info) . unwrap ( ) ;
126
- eprintln ! ( "{}: An unexpected Turbopack error occurred. Please report the content of {}, along with a description of what you were doing when the error occurred, to https://github.com/vercel/next.js/issues/new?template=1.bug_report.yml" , "FATAL" . red( ) . bold( ) , PANIC_LOG . to_string_lossy( ) ) ;
127
+ let internal_error_str: String = PrettyPrintError ( internal_error) . to_string ( ) ;
128
+ writeln ! ( log_file, "{}\n {}" , LOG_DIVIDER , & internal_error_str) . unwrap ( ) ;
129
+
130
+ let title = format ! (
131
+ "Turbopack Error: {}" ,
132
+ internal_error_str. lines( ) . next( ) . unwrap_or( "Unknown" )
133
+ ) ;
134
+ let new_discussion_url = if supports_hyperlinks:: supports_hyperlinks ( ) {
135
+ "clicking here." . hyperlink (
136
+ format ! (
137
+ "https://github.com/vercel/next.js/discussions/new?category=error-report&title={}&body={}&labels=Turbopack,Turbopack%20Panic%20Backtrace" ,
138
+ & urlencoding:: encode( & title) ,
139
+ & urlencoding:: encode( & format!( "Error message:\n ```\n {}\n ```" , & internal_error_str) )
140
+ )
141
+ )
142
+ } else {
143
+ format ! (
144
+ "clicking here: https://github.com/vercel/next.js/discussions/new?category=error-report&title={}&body={}&labels=Turbopack,Turbopack%20Panic%20Backtrace" ,
145
+ & urlencoding:: encode( & title) ,
146
+ & urlencoding:: encode( & format!( "Error message:\n ```\n {}\n ```" , title) )
147
+ )
148
+ } ;
149
+
150
+ eprintln ! (
151
+ "\n -----\n {}: An unexpected Turbopack error occurred. A panic log has been written to \
152
+ {}.\n \n To help make Turbopack better, report this error by {}\n -----\n ",
153
+ "FATAL" . red( ) . bold( ) ,
154
+ PANIC_LOG . to_string_lossy( ) ,
155
+ & new_discussion_url
156
+ ) ;
127
157
}
128
158
129
159
#[ napi]
0 commit comments