Skip to content

Commit 87ee630

Browse files
thomasballingerConvex, Inc.
authored andcommitted
Show errors from analyze (#38989)
Show output of console.log() and console.error() for deploys that fail due to a JavaScript error. Sometimes this is a validation error from a library that checks environment variables. GitOrigin-RevId: 7ae9c3ec19342ce999a4189763efcb72e095f890
1 parent 4b61339 commit 87ee630

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

crates/isolate/src/environment/analyze.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{
22
collections::{
33
btree_map::Entry,
44
BTreeMap,
5+
VecDeque,
56
},
67
path::Path,
78
str::FromStr,
@@ -132,14 +133,22 @@ pub struct AnalyzeEnvironment {
132133
rng: ChaCha12Rng,
133134
unix_timestamp: UnixTimestamp,
134135
environment_variables: BTreeMap<EnvVarName, EnvVarValue>,
136+
// Collect logs during analysis for push failure reporting (max 100 entries)
137+
collected_logs: VecDeque<String>,
135138
}
136139

137140
impl<RT: Runtime> IsolateEnvironment<RT> for AnalyzeEnvironment {
138141
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);
143152
Ok(())
144153
}
145154

@@ -279,6 +288,7 @@ impl AnalyzeEnvironment {
279288
rng,
280289
unix_timestamp,
281290
environment_variables,
291+
collected_logs: VecDeque::new(),
282292
};
283293
let client_id = Arc::new(client_id);
284294
let (handle, state) = isolate.start_request(client_id, environment).await?;
@@ -296,6 +306,13 @@ impl AnalyzeEnvironment {
296306
isolate_context.checkpoint();
297307
*isolate_clean = true;
298308

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+
299316
// Unlink the request from the isolate.
300317
// After this point, it's unsafe to run js code in the isolate that
301318
// expects the current request's environment.
@@ -307,6 +324,15 @@ impl AnalyzeEnvironment {
307324
if let Err(e) = handle.take_termination_error(None, "analyze")? {
308325
return Ok(Err(e));
309326
}
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+
310336
result
311337
}
312338

0 commit comments

Comments
 (0)