From e903a2b2dc7accc8cea953d6fb6e52835d44ea14 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Fri, 4 Feb 2022 20:09:25 +0100 Subject: [PATCH] full errors (#2454) --- deno_webgpu/src/error.rs | 63 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/deno_webgpu/src/error.rs b/deno_webgpu/src/error.rs index 26d7f7b246..204b525ce3 100644 --- a/deno_webgpu/src/error.rs +++ b/deno_webgpu/src/error.rs @@ -1,8 +1,9 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; use deno_core::ResourceId; use serde::Serialize; use std::convert::From; +use std::error::Error; use std::fmt; use wgpu_core::binding_model::CreateBindGroupError; use wgpu_core::binding_model::CreateBindGroupLayoutError; @@ -29,6 +30,18 @@ use wgpu_core::resource::CreateSamplerError; use wgpu_core::resource::CreateTextureError; use wgpu_core::resource::CreateTextureViewError; +fn fmt_err(err: &(dyn Error + 'static)) -> String { + let mut output = String::from(err.to_string()); + + let mut e = err.source(); + while let Some(source) = e { + output.push_str(&format!(": {source}")); + e = source.source(); + } + + output +} + #[derive(Serialize)] pub struct WebGpuResult { pub rid: Option, @@ -79,7 +92,7 @@ impl From for WebGpuError { match err { CreateBufferError::Device(err) => err.into(), CreateBufferError::AccessError(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -89,7 +102,7 @@ impl From for WebGpuError { match err { DeviceError::Lost => WebGpuError::Lost, DeviceError::OutOfMemory => WebGpuError::OutOfMemory, - DeviceError::Invalid => WebGpuError::Validation(err.to_string()), + DeviceError::Invalid => WebGpuError::Validation(fmt_err(&err)), } } } @@ -98,7 +111,7 @@ impl From for WebGpuError { fn from(err: BufferAccessError) -> Self { match err { BufferAccessError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -107,7 +120,7 @@ impl From for WebGpuError { fn from(err: CreateBindGroupLayoutError) -> Self { match err { CreateBindGroupLayoutError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -116,7 +129,7 @@ impl From for WebGpuError { fn from(err: CreatePipelineLayoutError) -> Self { match err { CreatePipelineLayoutError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -125,44 +138,44 @@ impl From for WebGpuError { fn from(err: CreateBindGroupError) -> Self { match err { CreateBindGroupError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } impl From for WebGpuError { fn from(err: RenderBundleError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } impl From for WebGpuError { fn from(err: CreateRenderBundleError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } impl From for WebGpuError { fn from(err: CopyError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } impl From for WebGpuError { fn from(err: CommandEncoderError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } impl From for WebGpuError { fn from(err: QueryError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } impl From for WebGpuError { fn from(err: ComputePassError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } @@ -170,14 +183,14 @@ impl From for WebGpuError { fn from(err: CreateComputePipelineError) -> Self { match err { CreateComputePipelineError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } impl From for WebGpuError { fn from(err: GetBindGroupLayoutError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } @@ -185,14 +198,14 @@ impl From for WebGpuError { fn from(err: CreateRenderPipelineError) -> Self { match err { CreateRenderPipelineError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } impl From for WebGpuError { fn from(err: RenderPassError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } @@ -200,7 +213,7 @@ impl From for WebGpuError { fn from(err: CreateSamplerError) -> Self { match err { CreateSamplerError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -209,7 +222,7 @@ impl From for WebGpuError { fn from(err: CreateShaderModuleError) -> Self { match err { CreateShaderModuleError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -218,14 +231,14 @@ impl From for WebGpuError { fn from(err: CreateTextureError) -> Self { match err { CreateTextureError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } impl From for WebGpuError { fn from(err: CreateTextureViewError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } } @@ -233,7 +246,7 @@ impl From for WebGpuError { fn from(err: CreateQuerySetError) -> Self { match err { CreateQuerySetError::Device(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -242,7 +255,7 @@ impl From for WebGpuError { fn from(err: QueueSubmitError) -> Self { match err { QueueSubmitError::Queue(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } @@ -251,14 +264,14 @@ impl From for WebGpuError { fn from(err: QueueWriteError) -> Self { match err { QueueWriteError::Queue(err) => err.into(), - err => WebGpuError::Validation(err.to_string()), + err => WebGpuError::Validation(fmt_err(&err)), } } } impl From for WebGpuError { fn from(err: ClearError) -> Self { - WebGpuError::Validation(err.to_string()) + WebGpuError::Validation(fmt_err(&err)) } }