diff --git a/Cargo.lock b/Cargo.lock index 878878bd077ba..2810131b81aa7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3453,9 +3453,9 @@ dependencies = [ [[package]] name = "human-panic" -version = "1.2.1" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82da652938b83f94cfdaaf9ae7aaadb8430d84b0dfda226998416318727eac2" +checksum = "c4f016c89920bbb30951a8405ecacbb4540db5524313b9445736e7e1855cf370" dependencies = [ "anstream", "anstyle", @@ -3463,7 +3463,7 @@ dependencies = [ "os_info", "serde", "serde_derive", - "toml 0.7.8", + "toml 0.8.14", "uuid", ] @@ -5215,13 +5215,13 @@ dependencies = [ [[package]] name = "os_info" -version = "3.7.0" +version = "3.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" dependencies = [ "log", "serde", - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -6995,9 +6995,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -9677,21 +9677,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.22.14", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] @@ -9706,20 +9706,20 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.15", ] [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.13", ] [[package]] @@ -10087,7 +10087,6 @@ dependencies = [ "anyhow", "assert_cmd", "build-target", - "human-panic", "itertools 0.10.5", "miette 5.10.0", "pretty_assertions", @@ -11245,6 +11244,7 @@ dependencies = [ "globwatch", "go-parse-duration", "hex", + "human-panic", "human_format", "humantime", "ignore", @@ -11530,7 +11530,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.4.6", + "rand 0.8.5", "static_assertions", ] @@ -12283,7 +12283,7 @@ dependencies = [ "serde_json", "serde_yaml 0.9.27", "thiserror", - "toml 0.8.2", + "toml 0.8.14", ] [[package]] @@ -12924,6 +12924,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.10.1" diff --git a/crates/turborepo-lib/Cargo.toml b/crates/turborepo-lib/Cargo.toml index 23b1dfc030508..1c24655c424cd 100644 --- a/crates/turborepo-lib/Cargo.toml +++ b/crates/turborepo-lib/Cargo.toml @@ -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" diff --git a/crates/turborepo-lib/src/lib.rs b/crates/turborepo-lib/src/lib.rs index 0de70d9982f3c..c853bf85a79af 100644 --- a/crates/turborepo-lib/src/lib.rs +++ b/crates/turborepo-lib/src/lib.rs @@ -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)] @@ -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; @@ -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, }; diff --git a/crates/turborepo-lib/src/panic_handler.rs b/crates/turborepo-lib/src/panic_handler.rs new file mode 100644 index 0000000000000..1faa49a3fcd63 --- /dev/null +++ b/crates/turborepo-lib/src/panic_handler.rs @@ -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 + ); +} diff --git a/crates/turborepo/Cargo.toml b/crates/turborepo/Cargo.toml index 71d99c5401ce4..f1331b13fa0ea 100644 --- a/crates/turborepo/Cargo.toml +++ b/crates/turborepo/Cargo.toml @@ -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 } diff --git a/crates/turborepo/src/main.rs b/crates/turborepo/src/main.rs index e00c9b6453748..ed293fca2c4f4 100644 --- a/crates/turborepo/src/main.rs +++ b/crates/turborepo/src/main.rs @@ -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)); diff --git a/crates/turborepo/src/panic_handler.rs b/crates/turborepo/src/panic_handler.rs deleted file mode 100644 index e404fe12efa0b..0000000000000 --- a/crates/turborepo/src/panic_handler.rs +++ /dev/null @@ -1,43 +0,0 @@ -use human_panic::report::{Method, Report}; -use turborepo_lib::get_version; - -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); - - let report_message = match report.persist() { - Ok(f) => { - format!( - "A report has been written to {}\n -Please open an issue at https://github.com/vercel/turbo/issues/new/choose \ - and include this file", - f.display() - ) - } - Err(e) => { - format!( - "An error has occurred while attempting to write a report.\n -Please open an issue at \ - https://github.com/vercel/turbo/issues/new/choose and include the following \ - error in your issue: {}", - e - ) - } - }; - - eprintln!( - "Oops! Turbo has crashed. - -{}", - report_message - ); -}