full errors (#2454)

This commit is contained in:
Leo Kettmeir
2022-02-04 20:09:25 +01:00
committed by GitHub
parent e50b62fae4
commit e903a2b2dc

View File

@@ -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<ResourceId>,
@@ -79,7 +92,7 @@ impl From<CreateBufferError> 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<DeviceError> 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<BufferAccessError> 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<CreateBindGroupLayoutError> 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<CreatePipelineLayoutError> 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<CreateBindGroupError> 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<RenderBundleError> for WebGpuError {
fn from(err: RenderBundleError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CreateRenderBundleError> for WebGpuError {
fn from(err: CreateRenderBundleError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CopyError> for WebGpuError {
fn from(err: CopyError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CommandEncoderError> for WebGpuError {
fn from(err: CommandEncoderError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<QueryError> for WebGpuError {
fn from(err: QueryError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<ComputePassError> for WebGpuError {
fn from(err: ComputePassError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@@ -170,14 +183,14 @@ impl From<CreateComputePipelineError> 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<GetBindGroupLayoutError> for WebGpuError {
fn from(err: GetBindGroupLayoutError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@@ -185,14 +198,14 @@ impl From<CreateRenderPipelineError> 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<RenderPassError> for WebGpuError {
fn from(err: RenderPassError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@@ -200,7 +213,7 @@ impl From<CreateSamplerError> 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<CreateShaderModuleError> 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<CreateTextureError> 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<CreateTextureViewError> for WebGpuError {
fn from(err: CreateTextureViewError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@@ -233,7 +246,7 @@ impl From<CreateQuerySetError> 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<QueueSubmitError> 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<QueueWriteError> 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<ClearError> for WebGpuError {
fn from(err: ClearError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}