@@ -215,7 +215,7 @@ impl GlobalPlay for wgc::global::Global {
215215 let ( cmd_buf, error) =
216216 self . command_encoder_finish ( encoder, & wgt:: CommandBufferDescriptor { label : None } ) ;
217217 if let Some ( e) = error {
218- panic ! ( "{e}" ) ;
218+ panic_with_error_chain ( e )
219219 }
220220 cmd_buf
221221 }
@@ -243,7 +243,7 @@ impl GlobalPlay for wgc::global::Global {
243243 Action :: CreateBuffer ( id, desc) => {
244244 let ( _, error) = self . device_create_buffer ( device, & desc, Some ( id) ) ;
245245 if let Some ( e) = error {
246- panic ! ( "{e}" ) ;
246+ panic_with_error_chain ( e )
247247 }
248248 }
249249 Action :: FreeBuffer ( id) => {
@@ -255,7 +255,7 @@ impl GlobalPlay for wgc::global::Global {
255255 Action :: CreateTexture ( id, desc) => {
256256 let ( _, error) = self . device_create_texture ( device, & desc, Some ( id) ) ;
257257 if let Some ( e) = error {
258- panic ! ( "{e}" ) ;
258+ panic_with_error_chain ( e )
259259 }
260260 }
261261 Action :: FreeTexture ( id) => {
@@ -271,7 +271,7 @@ impl GlobalPlay for wgc::global::Global {
271271 } => {
272272 let ( _, error) = self . texture_create_view ( parent_id, & desc, Some ( id) ) ;
273273 if let Some ( e) = error {
274- panic ! ( "{e}" ) ;
274+ panic_with_error_chain ( e )
275275 }
276276 }
277277 Action :: DestroyTextureView ( id) => {
@@ -280,7 +280,7 @@ impl GlobalPlay for wgc::global::Global {
280280 Action :: CreateSampler ( id, desc) => {
281281 let ( _, error) = self . device_create_sampler ( device, & desc, Some ( id) ) ;
282282 if let Some ( e) = error {
283- panic ! ( "{e}" ) ;
283+ panic_with_error_chain ( e )
284284 }
285285 }
286286 Action :: DestroySampler ( id) => {
@@ -295,7 +295,7 @@ impl GlobalPlay for wgc::global::Global {
295295 Action :: CreateBindGroupLayout ( id, desc) => {
296296 let ( _, error) = self . device_create_bind_group_layout ( device, & desc, Some ( id) ) ;
297297 if let Some ( e) = error {
298- panic ! ( "{e}" ) ;
298+ panic_with_error_chain ( e )
299299 }
300300 }
301301 Action :: DestroyBindGroupLayout ( id) => {
@@ -304,7 +304,7 @@ impl GlobalPlay for wgc::global::Global {
304304 Action :: CreatePipelineLayout ( id, desc) => {
305305 let ( _, error) = self . device_create_pipeline_layout ( device, & desc, Some ( id) ) ;
306306 if let Some ( e) = error {
307- panic ! ( "{e}" ) ;
307+ panic_with_error_chain ( e )
308308 }
309309 }
310310 Action :: DestroyPipelineLayout ( id) => {
@@ -313,7 +313,7 @@ impl GlobalPlay for wgc::global::Global {
313313 Action :: CreateBindGroup ( id, desc) => {
314314 let ( _, error) = self . device_create_bind_group ( device, & desc, Some ( id) ) ;
315315 if let Some ( e) = error {
316- panic ! ( "{e}" ) ;
316+ panic_with_error_chain ( e )
317317 }
318318 }
319319 Action :: DestroyBindGroup ( id) => {
@@ -353,7 +353,7 @@ impl GlobalPlay for wgc::global::Global {
353353 let ( _, error) =
354354 self . device_create_compute_pipeline ( device, & desc, Some ( id) , implicit_ids) ;
355355 if let Some ( e) = error {
356- panic ! ( "{e}" ) ;
356+ panic_with_error_chain ( e )
357357 }
358358 }
359359 Action :: DestroyComputePipeline ( id) => {
@@ -374,7 +374,7 @@ impl GlobalPlay for wgc::global::Global {
374374 let ( _, error) =
375375 self . device_create_render_pipeline ( device, & desc, Some ( id) , implicit_ids) ;
376376 if let Some ( e) = error {
377- panic ! ( "{e}" ) ;
377+ panic_with_error_chain ( e )
378378 }
379379 }
380380 Action :: DestroyRenderPipeline ( id) => {
@@ -395,7 +395,7 @@ impl GlobalPlay for wgc::global::Global {
395395 Some ( id) ,
396396 ) ;
397397 if let Some ( e) = error {
398- panic ! ( "{e}" ) ;
398+ panic_with_error_chain ( e )
399399 }
400400 }
401401 Action :: DestroyRenderBundle ( id) => {
@@ -404,7 +404,7 @@ impl GlobalPlay for wgc::global::Global {
404404 Action :: CreateQuerySet { id, desc } => {
405405 let ( _, error) = self . device_create_query_set ( device, & desc, Some ( id) ) ;
406406 if let Some ( e) = error {
407- panic ! ( "{e}" ) ;
407+ panic_with_error_chain ( e )
408408 }
409409 }
410410 Action :: DestroyQuerySet ( id) => {
@@ -446,7 +446,7 @@ impl GlobalPlay for wgc::global::Global {
446446 Some ( comb_manager. process ( ) . into_command_encoder_id ( ) ) ,
447447 ) ;
448448 if let Some ( e) = error {
449- panic ! ( "{e}" ) ;
449+ panic_with_error_chain ( e )
450450 }
451451 let cmdbuf = self . encode_commands ( encoder, commands) ;
452452 self . queue_submit ( queue, & [ cmdbuf] ) . unwrap ( ) ;
@@ -466,3 +466,30 @@ impl GlobalPlay for wgc::global::Global {
466466 }
467467 }
468468}
469+
470+ fn panic_with_error_chain < E > ( e : E )
471+ where
472+ E : std:: error:: Error ,
473+ {
474+ use std:: fmt:: Write ;
475+
476+ let mut err_msg = String :: new ( ) ;
477+
478+ write ! ( err_msg, "{e}" ) . unwrap ( ) ;
479+
480+ if let Some ( source) = e. source ( ) {
481+ if source. source ( ) . is_some ( ) {
482+ write ! ( err_msg, "\n Caused by:" ) . unwrap ( ) ;
483+ let mut prev_err: & dyn std:: error:: Error = & source;
484+ let mut idx = 0u64 ;
485+ while let Some ( source) = prev_err. source ( ) {
486+ write ! ( err_msg, "\n {idx}: {source}" ) . unwrap ( ) ;
487+ idx += 1 ;
488+ prev_err = source;
489+ }
490+ } else {
491+ write ! ( err_msg, "\n Caused by: {source}" ) . unwrap ( ) ;
492+ }
493+ }
494+ panic ! ( "encountered error: {err_msg}" )
495+ }
0 commit comments