Unverified Commit 88832a97 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

[Turbopack] report error to stderr when an error in a subscribtion happens (#69977)

### What?

report error to stderr when an error in a subscribtion happens
parent 1bcf0be9
...@@ -81,7 +81,7 @@ static ALLOC: dhat::Alloc = dhat::Alloc; ...@@ -81,7 +81,7 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
fn init() { fn init() {
set_hook(Box::new(|panic_info| { set_hook(Box::new(|panic_info| {
util::log_panic_and_inform(format!( util::log_internal_error_and_inform(&format!(
"Panic: {}\nBacktrace: {:?}", "Panic: {}\nBacktrace: {:?}",
panic_info, panic_info,
Backtrace::new() Backtrace::new()
......
...@@ -48,7 +48,7 @@ use super::{ ...@@ -48,7 +48,7 @@ use super::{
TurbopackResult, VcArc, TurbopackResult, VcArc,
}, },
}; };
use crate::{register, util::log_panic_and_inform}; use crate::register;
/// Used by [`benchmark_file_io`]. This is a noisy benchmark, so set the /// Used by [`benchmark_file_io`]. This is a noisy benchmark, so set the
/// threshold high. /// threshold high.
...@@ -736,8 +736,7 @@ pub fn project_hmr_events( ...@@ -736,8 +736,7 @@ pub fn project_hmr_events(
let update = hmr_update(project, identifier.clone(), state) let update = hmr_update(project, identifier.clone(), state)
.strongly_consistent() .strongly_consistent()
.await .await?;
.inspect_err(|e| log_panic_and_inform(e))?;
let HmrUpdateWithIssues { let HmrUpdateWithIssues {
update, update,
issues, issues,
......
...@@ -17,6 +17,8 @@ use turbopack_core::{ ...@@ -17,6 +17,8 @@ use turbopack_core::{
source_pos::SourcePos, source_pos::SourcePos,
}; };
use crate::util::log_internal_error_and_inform;
/// A helper type to hold both a Vc operation and the TurboTasks root process. /// A helper type to hold both a Vc operation and the TurboTasks root process.
/// Without this, we'd need to pass both individually all over the place /// Without this, we'd need to pass both individually all over the place
#[derive(Clone)] #[derive(Clone)]
...@@ -312,7 +314,11 @@ pub fn subscribe<T: 'static + Send + Sync, F: Future<Output = Result<T>> + Send, ...@@ -312,7 +314,11 @@ pub fn subscribe<T: 'static + Send + Sync, F: Future<Output = Result<T>> + Send,
let result = handler().await; let result = handler().await;
let status = func.call( let status = func.call(
result.map_err(|e| napi::Error::from_reason(PrettyPrintError(&e).to_string())), result.map_err(|e| {
let error = PrettyPrintError(&e).to_string();
log_internal_error_and_inform(&error);
napi::Error::from_reason(error)
}),
ThreadsafeFunctionCallMode::NonBlocking, ThreadsafeFunctionCallMode::NonBlocking,
); );
if !matches!(status, Status::Ok) { if !matches!(status, Status::Ok) {
......
...@@ -29,7 +29,6 @@ DEALINGS IN THE SOFTWARE. ...@@ -29,7 +29,6 @@ DEALINGS IN THE SOFTWARE.
use std::{ use std::{
cell::RefCell, cell::RefCell,
env, env,
fmt::Debug,
fs::OpenOptions, fs::OpenOptions,
io::{self, BufRead, Write}, io::{self, BufRead, Write},
path::PathBuf, path::PathBuf,
...@@ -52,13 +51,13 @@ static PANIC_LOG: Lazy<PathBuf> = Lazy::new(|| { ...@@ -52,13 +51,13 @@ static PANIC_LOG: Lazy<PathBuf> = Lazy::new(|| {
path path
}); });
pub fn log_panic_and_inform(err_info: impl Debug) { pub fn log_internal_error_and_inform(err_info: &str) {
if cfg!(debug_assertions) if cfg!(debug_assertions)
|| env::var("SWC_DEBUG") == Ok("1".to_string()) || env::var("SWC_DEBUG") == Ok("1".to_string())
|| env::var("CI").is_ok_and(|v| !v.is_empty()) || env::var("CI").is_ok_and(|v| !v.is_empty())
{ {
eprintln!( eprintln!(
"{}: An unexpected Turbopack error occurred:\n{:?}", "{}: An unexpected Turbopack error occurred:\n{}",
"FATAL".red().bold(), "FATAL".red().bold(),
err_info err_info
); );
...@@ -121,7 +120,7 @@ pub fn log_panic_and_inform(err_info: impl Debug) { ...@@ -121,7 +120,7 @@ pub fn log_panic_and_inform(err_info: impl Debug) {
.open(PANIC_LOG.as_path()) .open(PANIC_LOG.as_path())
.unwrap_or_else(|_| panic!("Failed to open {}", PANIC_LOG.to_string_lossy())); .unwrap_or_else(|_| panic!("Failed to open {}", PANIC_LOG.to_string_lossy()));
writeln!(log_file, "{}\n{:?}", LOG_DIVIDER, err_info).unwrap(); writeln!(log_file, "{}\n{}", LOG_DIVIDER, err_info).unwrap();
eprintln!("{}: An unexpected Turbopack error occurred. Please report the content of {} to https://github.com/vercel/next.js/issues/new", "FATAL".red().bold(), PANIC_LOG.to_string_lossy()); eprintln!("{}: An unexpected Turbopack error occurred. Please report the content of {} to https://github.com/vercel/next.js/issues/new", "FATAL".red().bold(), PANIC_LOG.to_string_lossy());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment