@@ -193,15 +193,59 @@ ThunkFailedException(thunk, origin, ex::E) where E =
193193 ThunkFailedException {E} (convert (WeakThunk, thunk), convert (WeakThunk, origin), ex)
194194function Base. showerror (io:: IO , ex:: ThunkFailedException )
195195 t = unwrap_weak (ex. thunk)
196- o = unwrap_weak (ex. origin)
197- t_str = t != = nothing ? " $t " : " ?"
198- o_str = o != = nothing ? " $o " : " ?"
196+
197+ # Find root-cause thunk
198+ last_tfex = ex
199+ failed_tasks = Union{Thunk,Nothing}[]
200+ while last_tfex. ex isa ThunkFailedException && unwrap_weak (last_tfex. ex. origin) != = nothing
201+ push! (failed_tasks, unwrap_weak (last_tfex. thunk))
202+ last_tfex = last_tfex. ex
203+ end
204+ o = unwrap_weak (last_tfex. origin)
205+ root_ex = last_tfex. ex
206+
207+ function thunk_string (t)
208+ if t === nothing
209+ return " Thunk(?)"
210+ end
211+ Tinputs = Any[]
212+ for input in t. inputs
213+ input = unwrap_weak (input)
214+ if istask (input)
215+ push! (Tinputs, " Thunk(id=$(input. id) )" )
216+ else
217+ push! (Tinputs, input)
218+ end
219+ end
220+ t_sig = if length (Tinputs) <= 4
221+ " $(t. f) ($(join (Tinputs, " , " )) ))"
222+ else
223+ " $(t. f) ($(length (Tinputs)) inputs...)"
224+ end
225+ return " Thunk(id=$(t. id) , $t_sig "
226+ end
227+ t_str = thunk_string (t)
228+ o_str = thunk_string (o)
199229 t_id = t != = nothing ? t. id : ' ?'
200230 o_id = o != = nothing ? o. id : ' ?'
201- println (io, " ThunkFailedException ($t failure" ,
202- (o != = nothing && t != o) ? " due to a failure in $o )" : " )" ,
203- " :" )
204- Base. showerror (io, ex. ex)
231+ println (io, " ThunkFailedException:" )
232+ println (io, " Root Exception Type: $(typeof (root_ex)) " )
233+ println (io, " Root Exception:" )
234+ Base. showerror (io, root_ex); println (io)
235+ if t != = o
236+ println (io, " Root Thunk: $o_str " )
237+ if length (failed_tasks) <= 4
238+ for i in failed_tasks
239+ i_str = thunk_string (i)
240+ println (io, " Inner Thunk: $i_str " )
241+ end
242+ else
243+ println (io, " ..." )
244+ println (io, " $(length (failed_tasks)) Inner Thunks..." )
245+ println (io, " ..." )
246+ end
247+ end
248+ print (io, " This Thunk: $t_str " )
205249end
206250
207251"""
0 commit comments