11use std:: {
2+ borrow:: Cow ,
23 error:: Error ,
34 fmt:: { self , Debug , Display } ,
45 future:: Future ,
@@ -11,7 +12,9 @@ use std::{
1112use anyhow:: { Result , anyhow} ;
1213use auto_hash_map:: AutoMap ;
1314use rustc_hash:: FxHasher ;
15+ use serde:: { Deserialize , Serialize } ;
1416use tracing:: Span ;
17+ use turbo_rcstr:: RcStr ;
1518
1619pub use crate :: id:: BackendJobId ;
1720use crate :: {
@@ -401,9 +404,9 @@ pub type TaskCollectiblesMap = AutoMap<RawVc, i32, BuildHasherDefault<FxHasher>,
401404
402405// Structurally and functionally similar to Cow<&'static, str> but explicitly notes the importance
403406// of non-static strings potentially containing PII (Personal Identifiable Information).
404- #[ derive( Clone , Debug ) ]
407+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq , Eq ) ]
405408pub enum TurboTasksExecutionErrorMessage {
406- PIISafe ( & ' static str ) ,
409+ PIISafe ( Cow < ' static , str > ) ,
407410 NonPIISafe ( String ) ,
408411}
409412
@@ -416,16 +419,32 @@ impl Display for TurboTasksExecutionErrorMessage {
416419 }
417420}
418421
419- #[ derive( Debug , Clone ) ]
422+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
420423pub struct TurboTasksError {
421424 pub message : TurboTasksExecutionErrorMessage ,
422425 pub source : Option < TurboTasksExecutionError > ,
423426}
424427
425- #[ derive( Clone , Debug ) ]
428+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
429+ pub struct TurboTaskContextError {
430+ pub task : RcStr ,
431+ pub source : Option < TurboTasksExecutionError > ,
432+ }
433+
434+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq , Eq ) ]
426435pub enum TurboTasksExecutionError {
427436 Panic ( Arc < TurboTasksPanic > ) ,
428437 Error ( Arc < TurboTasksError > ) ,
438+ TaskContext ( Arc < TurboTaskContextError > ) ,
439+ }
440+
441+ impl TurboTasksExecutionError {
442+ pub fn task_context ( & self , task : impl Display ) -> Self {
443+ TurboTasksExecutionError :: TaskContext ( Arc :: new ( TurboTaskContextError {
444+ task : RcStr :: from ( task. to_string ( ) ) ,
445+ source : Some ( self . clone ( ) ) ,
446+ } ) )
447+ }
429448}
430449
431450impl Error for TurboTasksExecutionError {
@@ -435,6 +454,9 @@ impl Error for TurboTasksExecutionError {
435454 TurboTasksExecutionError :: Error ( error) => {
436455 error. source . as_ref ( ) . map ( |s| s as & dyn Error )
437456 }
457+ TurboTasksExecutionError :: TaskContext ( context_error) => {
458+ context_error. source . as_ref ( ) . map ( |s| s as & dyn Error )
459+ }
438460 }
439461 }
440462}
@@ -446,6 +468,9 @@ impl Display for TurboTasksExecutionError {
446468 TurboTasksExecutionError :: Error ( error) => {
447469 write ! ( f, "{}" , error. message)
448470 }
471+ TurboTasksExecutionError :: TaskContext ( context_error) => {
472+ write ! ( f, "Execution of {} failed" , context_error. task)
473+ }
449474 }
450475 }
451476}
@@ -534,7 +559,7 @@ pub trait Backend: Sync + Send {
534559 fn task_execution_result (
535560 & self ,
536561 task_id : TaskId ,
537- result : Result < RawVc , Arc < TurboTasksExecutionError > > ,
562+ result : Result < RawVc , TurboTasksExecutionError > ,
538563 turbo_tasks : & dyn TurboTasksBackendApi < Self > ,
539564 ) ;
540565
0 commit comments