@@ -2,6 +2,7 @@ use std::{
2
2
collections:: {
3
3
btree_map:: Entry ,
4
4
BTreeMap ,
5
+ VecDeque ,
5
6
} ,
6
7
path:: Path ,
7
8
str:: FromStr ,
@@ -132,14 +133,22 @@ pub struct AnalyzeEnvironment {
132
133
rng : ChaCha12Rng ,
133
134
unix_timestamp : UnixTimestamp ,
134
135
environment_variables : BTreeMap < EnvVarName , EnvVarValue > ,
136
+ // Collect logs during analysis for push failure reporting (max 100 entries)
137
+ collected_logs : VecDeque < String > ,
135
138
}
136
139
137
140
impl < RT : Runtime > IsolateEnvironment < RT > for AnalyzeEnvironment {
138
141
fn trace ( & mut self , _level : LogLevel , messages : Vec < String > ) -> anyhow:: Result < ( ) > {
139
- tracing:: warn!(
140
- "Unexpected Console access at import time: {}" ,
141
- messages. join( " " )
142
- ) ;
142
+ // These logs are only shown to the pusher on error.
143
+ let log_message = messages. join ( " " ) ;
144
+
145
+ // Keep only the last 100 log entries
146
+ if self . collected_logs . len ( ) >= 100 {
147
+ self . collected_logs . pop_front ( ) ;
148
+ }
149
+ self . collected_logs . push_back ( log_message. clone ( ) ) ;
150
+
151
+ tracing:: warn!( "Console access at import time: {}" , log_message) ;
143
152
Ok ( ( ) )
144
153
}
145
154
@@ -279,6 +288,7 @@ impl AnalyzeEnvironment {
279
288
rng,
280
289
unix_timestamp,
281
290
environment_variables,
291
+ collected_logs : VecDeque :: new ( ) ,
282
292
} ;
283
293
let client_id = Arc :: new ( client_id) ;
284
294
let ( handle, state) = isolate. start_request ( client_id, environment) . await ?;
@@ -296,6 +306,13 @@ impl AnalyzeEnvironment {
296
306
isolate_context. checkpoint ( ) ;
297
307
* isolate_clean = true ;
298
308
309
+ let error_logs = if let Ok ( Err ( _) ) = result {
310
+ let state = isolate_context. take_state ( ) . expect ( "Lost RequestState?" ) ;
311
+ state. environment . collected_logs . clone ( )
312
+ } else {
313
+ VecDeque :: new ( )
314
+ } ;
315
+
299
316
// Unlink the request from the isolate.
300
317
// After this point, it's unsafe to run js code in the isolate that
301
318
// expects the current request's environment.
@@ -307,6 +324,15 @@ impl AnalyzeEnvironment {
307
324
if let Err ( e) = handle. take_termination_error ( None , "analyze" ) ? {
308
325
return Ok ( Err ( e) ) ;
309
326
}
327
+
328
+ if let Ok ( Err ( mut js_error) ) = result {
329
+ if !error_logs. is_empty ( ) {
330
+ let logs_text = error_logs. iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ;
331
+ js_error. message = format ! ( "{}\n \n {}" , js_error. message, logs_text) ;
332
+ }
333
+ return Ok ( Err ( js_error) ) ;
334
+ }
335
+
310
336
result
311
337
}
312
338
0 commit comments