Skip to content

Turbopack: persist and compare errors and panics #77935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: sokra/next-font-specific-error
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
thread::available_parallelism,
};

use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use auto_hash_map::{AutoMap, AutoSet};
use indexmap::IndexSet;
use parking_lot::{Condvar, Mutex};
Expand Down Expand Up @@ -567,38 +567,46 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {

if let Some(output) = get!(task, Output) {
let result = match output {
OutputValue::Cell(cell) => Some(Ok(Ok(RawVc::TaskCell(cell.task, cell.cell)))),
OutputValue::Output(task) => Some(Ok(Ok(RawVc::TaskOutput(*task)))),
OutputValue::Error | OutputValue::Panic => {
get!(task, Error).map(|error| Err(error.clone().into()))
OutputValue::Cell(cell) => Ok(Ok(RawVc::TaskCell(cell.task, cell.cell))),
OutputValue::Output(task) => Ok(Ok(RawVc::TaskOutput(*task))),
OutputValue::Error(error) => {
let err: anyhow::Error = error.clone().into();
Err(err.context(format!(
"Execution of {} failed",
ctx.get_task_description(task_id)
)))
}
OutputValue::Panic(Some(panic)) => Err(anyhow!(
"Panic in {}: {}",
ctx.get_task_description(task_id),
panic
)),
OutputValue::Panic(None) => {
Err(anyhow!("Panic in {}", ctx.get_task_description(task_id)))
}
};
if let Some(result) = result {
if self.should_track_dependencies() {
if let Some(reader) = reader {
let _ = task.add(CachedDataItem::OutputDependent {
task: reader,
if self.should_track_dependencies() {
if let Some(reader) = reader {
let _ = task.add(CachedDataItem::OutputDependent {
task: reader,
value: (),
});
drop(task);

let mut reader_task = ctx.task(reader, TaskDataCategory::Data);
if reader_task
.remove(&CachedDataItemKey::OutdatedOutputDependency { target: task_id })
.is_none()
{
let _ = reader_task.add(CachedDataItem::OutputDependency {
target: task_id,
value: (),
});
drop(task);

let mut reader_task = ctx.task(reader, TaskDataCategory::Data);
if reader_task
.remove(&CachedDataItemKey::OutdatedOutputDependency {
target: task_id,
})
.is_none()
{
let _ = reader_task.add(CachedDataItem::OutputDependency {
target: task_id,
value: (),
});
}
}
}

return result;
}

return result;
}

let reader_desc = reader.map(|r| self.get_task_desc_fn(r));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, mem::take};

use anyhow::{anyhow, Result};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use turbo_tasks::{util::SharedError, RawVc, TaskId};

Expand Down Expand Up @@ -65,7 +65,6 @@ impl UpdateOutputOperation {
.then(|| new_children.iter().copied().collect())
.unwrap_or_default();

let old_error = task.remove(&CachedDataItemKey::Error {});
let current_output = get!(task, Output);
let output_value = match output {
Ok(Ok(RawVc::TaskOutput(output_task_id))) => {
Expand Down Expand Up @@ -95,23 +94,20 @@ impl UpdateOutputOperation {
panic!("LocalOutput must not be output of a task");
}
Ok(Err(err)) => {
task.insert(CachedDataItem::Error {
value: SharedError::new(err.context(format!(
"Execution of {} failed",
ctx.get_task_description(task_id)
))),
});
OutputValue::Error
if let Some(OutputValue::Error(old_error)) = current_output {
if old_error.eq_stack(&err) {
return;
}
}
OutputValue::Error(SharedError::new(err))
}
Err(panic) => {
task.insert(CachedDataItem::Error {
value: SharedError::new(anyhow!(
"Panic in {}: {:?}",
ctx.get_task_description(task_id),
panic
)),
});
OutputValue::Panic
if let Some(OutputValue::Panic(old_panic)) = current_output {
if old_panic.as_deref() == panic.as_deref() {
return;
}
}
OutputValue::Panic(panic.map(|s| s.into()))
}
};
let old_content = task.insert(CachedDataItem::Output {
Expand All @@ -137,7 +133,6 @@ impl UpdateOutputOperation {

drop(task);
drop(old_content);
drop(old_error);

UpdateOutputOperation::MakeDependentTasksDirty {
#[cfg(feature = "trace_task_dirty")]
Expand Down
21 changes: 6 additions & 15 deletions turbopack/crates/turbo-tasks-backend/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cmp::Ordering;

use rustc_hash::FxHashSet;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{
event::{Event, EventListener},
registry,
Expand Down Expand Up @@ -52,20 +53,20 @@ pub struct CollectiblesRef {
pub collectible_type: TraitTypeId,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum OutputValue {
Cell(CellRef),
Output(TaskId),
Error,
Panic,
Error(SharedError),
Panic(Option<RcStr>),
}
impl OutputValue {
fn is_transient(&self) -> bool {
match self {
OutputValue::Cell(cell) => cell.task.is_transient(),
OutputValue::Output(task) => task.is_transient(),
OutputValue::Error => false,
OutputValue::Panic => false,
OutputValue::Error(_) => false,
OutputValue::Panic(_) => false,
}
}
}
Expand Down Expand Up @@ -488,12 +489,6 @@ pub enum CachedDataItem {
target: CollectiblesRef,
value: (),
},

// Transient Error State
#[serde(skip)]
Error {
value: SharedError,
},
}

impl CachedDataItem {
Expand Down Expand Up @@ -529,7 +524,6 @@ impl CachedDataItem {
CachedDataItem::OutdatedOutputDependency { .. } => false,
CachedDataItem::OutdatedCellDependency { .. } => false,
CachedDataItem::OutdatedCollectiblesDependency { .. } => false,
CachedDataItem::Error { .. } => false,
}
}

Expand Down Expand Up @@ -584,7 +578,6 @@ impl CachedDataItem {
| Self::OutdatedCollectiblesDependency { .. }
| Self::InProgressCell { .. }
| Self::InProgress { .. }
| Self::Error { .. }
| Self::Activeness { .. } => TaskDataCategory::All,
}
}
Expand Down Expand Up @@ -623,7 +616,6 @@ impl CachedDataItemKey {
CachedDataItemKey::OutdatedOutputDependency { .. } => false,
CachedDataItemKey::OutdatedCellDependency { .. } => false,
CachedDataItemKey::OutdatedCollectiblesDependency { .. } => false,
CachedDataItemKey::Error { .. } => false,
}
}

Expand Down Expand Up @@ -666,7 +658,6 @@ impl CachedDataItemType {
| Self::OutdatedCollectiblesDependency { .. }
| Self::InProgressCell { .. }
| Self::InProgress { .. }
| Self::Error { .. }
| Self::Activeness { .. } => TaskDataCategory::All,
}
}
Expand Down
21 changes: 21 additions & 0 deletions turbopack/crates/turbo-tasks/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ impl SharedError {
inner: Arc::new(err),
}
}

pub fn eq_stack(&self, other: &anyhow::Error) -> bool {
if self.to_string() != other.to_string() {
return false;
}
let mut source = self.source();
let mut other_source = other.source();
loop {
if source.is_none() && other_source.is_none() {
return true;
}
let (Some(source_err), Some(other_source_err)) = (source, other_source) else {
return false;
};
if source_err.to_string() != other_source_err.to_string() {
return false;
}
source = source_err.source();
other_source = other_source_err.source();
}
}
}

impl StdError for SharedError {
Expand Down
Loading