Skip to content

Commit f0d4768

Browse files
fix: disable panic handler in ci (#8436)
### Description When running in CI persisting the panic backtrace to a tempfile makes it harder (or impossible) to get the entire backtrace. This PR changes our behavior to no longer will persist the backtrace to a file if we detect we're running in CI or a vendor, instead we include the serialized backtrace in the message we print to the console. First commit is moving the panic handler to the library crate to avoid adding dependencies to the binary crate. ### Testing Instructions ``` [0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ turbo_dev --version Oops! Turbo has crashed. A report has been written to /var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/report-319148de-342d-49f8-a87c-aa9c6d7b0cbd.toml Please open an issue at https://github.com/vercel/turbo/issues/new/choose and include this file [101 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ CI=1 turbo_dev --version Oops! Turbo has crashed. Caused by "name" = "turbo" "operating_system" = "Mac OS 14.4.1 [64-bit]" "crate_version" = "2.0.4-canary.1" "explanation" = """ file 'crates/turborepo/src/main.rs' at line 13 """ "cause" = "Forced panic!" "method" = "Panic" "backtrace" = """ 0: 0x100d22678 - core::panicking::panic_fmt::hc04a814f639f8411 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/panicking.rs:72 1: 0x100c78f30 - turbo[48bd35f77d4e47ef]::main at /Users/olszewski/code/vercel/turborepo/crates/turborepo/src/main.rs:13 2: 0x100c78fc0 - <fn() -> core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error> as core[5c1d1104bc1ee810]::ops::function::FnOnce<()>>::call_once at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/ops/function.rs:250 3: 0x100c79198 - std[4e9c1a951f116da0]::sys_common::backtrace::__rust_begin_short_backtrace::<fn() -> core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>, core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>> at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/sys_common/backtrace.rs:155 4: 0x100c79114 - std[4e9c1a951f116da0]::rt::lang_start::<core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>>::{closure#0} at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:159 5: 0x100d0233c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h0b62848974045da6 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/ops/function.rs:284 - std::panicking::try::do_call::h62aa855a2974a84f at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:559 - std::panicking::try::he4b3a2d91bf1dbbf at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:523 - std::panic::catch_unwind::h7420eceb348170da at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panic.rs:149 - std::rt::lang_start_internal::{{closure}}::h20b554397a83800b at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:141 - std::panicking::try::do_call::h4667a29b822d8c00 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:559 - std::panicking::try::h55eb6abb56c6f5e0 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:523 - std::panic::catch_unwind::he9dd44a8a626ad3d at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panic.rs:149 - std::rt::lang_start_internal::hacd033e6e2adb13b at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:141 6: 0x100c790e0 - std[4e9c1a951f116da0]::rt::lang_start::<core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>> at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:158 7: 0x100c78f54 - _main""" Please open an issue at https://github.com/vercel/turbo/issues/new/choose and include this message in your issue [101 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ GITHUB_ACTIONS=1 turbo_dev --version Oops! Turbo has crashed. Caused by "name" = "turbo" "operating_system" = "Mac OS 14.4.1 [64-bit]" "crate_version" = "2.0.4-canary.1" "explanation" = """ file 'crates/turborepo/src/main.rs' at line 13 """ "cause" = "Forced panic!" "method" = "Panic" "backtrace" = """ 0: 0x10254e678 - core::panicking::panic_fmt::hc04a814f639f8411 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/panicking.rs:72 1: 0x1024a4f30 - turbo[48bd35f77d4e47ef]::main at /Users/olszewski/code/vercel/turborepo/crates/turborepo/src/main.rs:13 2: 0x1024a4fc0 - <fn() -> core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error> as core[5c1d1104bc1ee810]::ops::function::FnOnce<()>>::call_once at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/ops/function.rs:250 3: 0x1024a5198 - std[4e9c1a951f116da0]::sys_common::backtrace::__rust_begin_short_backtrace::<fn() -> core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>, core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>> at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/sys_common/backtrace.rs:155 4: 0x1024a5114 - std[4e9c1a951f116da0]::rt::lang_start::<core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>>::{closure#0} at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:159 5: 0x10252e33c - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h0b62848974045da6 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/core/src/ops/function.rs:284 - std::panicking::try::do_call::h62aa855a2974a84f at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:559 - std::panicking::try::he4b3a2d91bf1dbbf at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:523 - std::panic::catch_unwind::h7420eceb348170da at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panic.rs:149 - std::rt::lang_start_internal::{{closure}}::h20b554397a83800b at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:141 - std::panicking::try::do_call::h4667a29b822d8c00 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:559 - std::panicking::try::h55eb6abb56c6f5e0 at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panicking.rs:523 - std::panic::catch_unwind::he9dd44a8a626ad3d at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/panic.rs:149 - std::rt::lang_start_internal::hacd033e6e2adb13b at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:141 6: 0x1024a50e0 - std[4e9c1a951f116da0]::rt::lang_start::<core[5c1d1104bc1ee810]::result::Result<(), anyhow[ba69079c3fe1888b]::Error>> at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/library/std/src/rt.rs:158 7: 0x1024a4f54 - _main""" Please open an issue at https://github.com/vercel/turbo/issues/new/choose and include this message in your issue ```
1 parent d79cc4f commit f0d4768

File tree

7 files changed

+93
-70
lines changed

7 files changed

+93
-70
lines changed

Cargo.lock

+29-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turborepo-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ globwalk = { version = "0.1.0", path = "../turborepo-globwalk" }
6161
globwatch = { path = "../turborepo-globwatch" }
6262
go-parse-duration = "0.1.1"
6363
hex = "0.4.3"
64+
human-panic = "1.2.1"
6465
human_format = "1.1.0"
6566
humantime = "2.1.0"
6667
ignore = "0.4.22"

crates/turborepo-lib/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(hash_extract_if)]
55
#![feature(option_get_or_insert_default)]
66
#![feature(once_cell_try)]
7+
#![feature(panic_info_message)]
78
#![feature(try_blocks)]
89
#![feature(impl_trait_in_assoc_type)]
910
#![deny(clippy::all)]
@@ -26,6 +27,7 @@ pub(crate) mod globwatcher;
2627
mod hash;
2728
mod opts;
2829
mod package_changes_watcher;
30+
mod panic_handler;
2931
mod process;
3032
mod rewrite_json;
3133
mod run;
@@ -41,6 +43,7 @@ pub use crate::{
4143
child::spawn_child,
4244
cli::Args,
4345
daemon::{DaemonClient, DaemonConnector, Paths as DaemonPaths},
46+
panic_handler::panic_handler,
4447
run::package_discovery::DaemonPackageDiscovery,
4548
};
4649

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use human_panic::report::{Method, Report};
2+
3+
use crate::get_version;
4+
5+
const OPEN_ISSUE_MESSAGE: &str =
6+
"Please open an issue at https://github.com/vercel/turbo/issues/new/choose";
7+
8+
pub fn panic_handler(panic_info: &std::panic::PanicInfo) {
9+
let cause = panic_info
10+
.message()
11+
.map(ToString::to_string)
12+
.unwrap_or_else(|| "Unknown".to_string());
13+
14+
let explanation = match panic_info.location() {
15+
Some(location) => format!("file '{}' at line {}\n", location.file(), location.line()),
16+
None => "unknown.".to_string(),
17+
};
18+
19+
let report = Report::new("turbo", get_version(), Method::Panic, explanation, cause);
20+
// If we're in CI we don't persist the backtrace to a temp file as this is hard
21+
// to retrieve.
22+
let should_persist = !turborepo_ci::is_ci() && turborepo_ci::Vendor::infer().is_none();
23+
24+
let report_message = if should_persist {
25+
match report.persist() {
26+
Ok(f) => {
27+
format!(
28+
"A report has been written to {}\n\n{OPEN_ISSUE_MESSAGE} and include this file",
29+
f.display()
30+
)
31+
}
32+
Err(e) => {
33+
format!(
34+
"An error has occurred while attempting to write a \
35+
report.\n\n{OPEN_ISSUE_MESSAGE} and include the following error in your \
36+
issue: {}",
37+
e
38+
)
39+
}
40+
}
41+
} else if let Some(backtrace) = report.serialize() {
42+
format!(
43+
"Caused by \n{backtrace}\n\n{OPEN_ISSUE_MESSAGE} and include this message in your \
44+
issue"
45+
)
46+
} else {
47+
format!(
48+
"Unable to serialize backtrace.\n\n{OPEN_ISSUE_MESSAGE} and include this message in \
49+
your issue"
50+
)
51+
};
52+
53+
eprintln!(
54+
"Oops! Turbo has crashed.
55+
56+
{}",
57+
report_message
58+
);
59+
}

crates/turborepo/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ workspace = true
2828

2929
[dependencies]
3030
anyhow = { workspace = true, features = ["backtrace"] }
31-
human-panic = "1.2.1"
3231
miette.workspace = true
3332
turborepo-lib = { workspace = true, default-features = false }
3433

crates/turborepo/src/main.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
#![feature(panic_info_message)]
21
#![deny(clippy::all)]
32

4-
mod panic_handler;
5-
63
use std::process;
74

85
use anyhow::Result;
96
use miette::Report;
107

11-
use crate::panic_handler::panic_handler;
12-
138
// This function should not expanded. Please add any logic to
149
// `turborepo_lib::main` instead
1510
fn main() -> Result<()> {
16-
std::panic::set_hook(Box::new(panic_handler));
11+
std::panic::set_hook(Box::new(turborepo_lib::panic_handler));
1712

1813
let exit_code = turborepo_lib::main().unwrap_or_else(|err| {
1914
println!("{:?}", Report::new(err));

crates/turborepo/src/panic_handler.rs

-43
This file was deleted.

0 commit comments

Comments
 (0)