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;
fn init() {
set_hook(Box::new(|panic_info| {
util::log_panic_and_inform(format!(
util::log_internal_error_and_inform(&format!(
"Panic: {}\nBacktrace: {:?}",
panic_info,
Backtrace::new()
......
......@@ -48,7 +48,7 @@ use super::{
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
/// threshold high.
......@@ -736,8 +736,7 @@ pub fn project_hmr_events(
let update = hmr_update(project, identifier.clone(), state)
.strongly_consistent()
.await
.inspect_err(|e| log_panic_and_inform(e))?;
.await?;
let HmrUpdateWithIssues {
update,
issues,
......
......@@ -17,6 +17,8 @@ use turbopack_core::{
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.
/// Without this, we'd need to pass both individually all over the place
#[derive(Clone)]
......@@ -312,7 +314,11 @@ pub fn subscribe<T: 'static + Send + Sync, F: Future<Output = Result<T>> + Send,
let result = handler().await;
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,
);
if !matches!(status, Status::Ok) {
......
......@@ -29,7 +29,6 @@ DEALINGS IN THE SOFTWARE.
use std::{
cell::RefCell,
env,
fmt::Debug,
fs::OpenOptions,
io::{self, BufRead, Write},
path::PathBuf,
......@@ -52,13 +51,13 @@ static PANIC_LOG: Lazy<PathBuf> = Lazy::new(|| {
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)
|| env::var("SWC_DEBUG") == Ok("1".to_string())
|| env::var("CI").is_ok_and(|v| !v.is_empty())
{
eprintln!(
"{}: An unexpected Turbopack error occurred:\n{:?}",
"{}: An unexpected Turbopack error occurred:\n{}",
"FATAL".red().bold(),
err_info
);
......@@ -121,7 +120,7 @@ pub fn log_panic_and_inform(err_info: impl Debug) {
.open(PANIC_LOG.as_path())
.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());
}
......
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