Skip to content

Commit

Permalink
fix: disable panic handler in ci (#8436)
Browse files Browse the repository at this point in the history
### 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
```
  • Loading branch information
chris-olszewski committed Jun 11, 2024
1 parent d79cc4f commit f0d4768
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 70 deletions.
49 changes: 29 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ globwalk = { version = "0.1.0", path = "../turborepo-globwalk" }
globwatch = { path = "../turborepo-globwatch" }
go-parse-duration = "0.1.1"
hex = "0.4.3"
human-panic = "1.2.1"
human_format = "1.1.0"
humantime = "2.1.0"
ignore = "0.4.22"
Expand Down
3 changes: 3 additions & 0 deletions crates/turborepo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(hash_extract_if)]
#![feature(option_get_or_insert_default)]
#![feature(once_cell_try)]
#![feature(panic_info_message)]
#![feature(try_blocks)]
#![feature(impl_trait_in_assoc_type)]
#![deny(clippy::all)]
Expand All @@ -26,6 +27,7 @@ pub(crate) mod globwatcher;
mod hash;
mod opts;
mod package_changes_watcher;
mod panic_handler;
mod process;
mod rewrite_json;
mod run;
Expand All @@ -41,6 +43,7 @@ pub use crate::{
child::spawn_child,
cli::Args,
daemon::{DaemonClient, DaemonConnector, Paths as DaemonPaths},
panic_handler::panic_handler,
run::package_discovery::DaemonPackageDiscovery,
};

Expand Down
59 changes: 59 additions & 0 deletions crates/turborepo-lib/src/panic_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use human_panic::report::{Method, Report};

use crate::get_version;

const OPEN_ISSUE_MESSAGE: &str =
"Please open an issue at https://github.com/vercel/turbo/issues/new/choose";

pub fn panic_handler(panic_info: &std::panic::PanicInfo) {
let cause = panic_info
.message()
.map(ToString::to_string)
.unwrap_or_else(|| "Unknown".to_string());

let explanation = match panic_info.location() {
Some(location) => format!("file '{}' at line {}\n", location.file(), location.line()),
None => "unknown.".to_string(),
};

let report = Report::new("turbo", get_version(), Method::Panic, explanation, cause);
// If we're in CI we don't persist the backtrace to a temp file as this is hard
// to retrieve.
let should_persist = !turborepo_ci::is_ci() && turborepo_ci::Vendor::infer().is_none();

let report_message = if should_persist {
match report.persist() {
Ok(f) => {
format!(
"A report has been written to {}\n\n{OPEN_ISSUE_MESSAGE} and include this file",
f.display()
)
}
Err(e) => {
format!(
"An error has occurred while attempting to write a \
report.\n\n{OPEN_ISSUE_MESSAGE} and include the following error in your \
issue: {}",
e
)
}
}
} else if let Some(backtrace) = report.serialize() {
format!(
"Caused by \n{backtrace}\n\n{OPEN_ISSUE_MESSAGE} and include this message in your \
issue"
)
} else {
format!(
"Unable to serialize backtrace.\n\n{OPEN_ISSUE_MESSAGE} and include this message in \
your issue"
)
};

eprintln!(
"Oops! Turbo has crashed.
{}",
report_message
);
}
1 change: 0 additions & 1 deletion crates/turborepo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ workspace = true

[dependencies]
anyhow = { workspace = true, features = ["backtrace"] }
human-panic = "1.2.1"
miette.workspace = true
turborepo-lib = { workspace = true, default-features = false }

Expand Down
7 changes: 1 addition & 6 deletions crates/turborepo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#![feature(panic_info_message)]
#![deny(clippy::all)]

mod panic_handler;

use std::process;

use anyhow::Result;
use miette::Report;

use crate::panic_handler::panic_handler;

// This function should not expanded. Please add any logic to
// `turborepo_lib::main` instead
fn main() -> Result<()> {
std::panic::set_hook(Box::new(panic_handler));
std::panic::set_hook(Box::new(turborepo_lib::panic_handler));

let exit_code = turborepo_lib::main().unwrap_or_else(|err| {
println!("{:?}", Report::new(err));
Expand Down
43 changes: 0 additions & 43 deletions crates/turborepo/src/panic_handler.rs

This file was deleted.

0 comments on commit f0d4768

Please sign in to comment.