Skip to content

Commit 7b3da03

Browse files
WIP: feat(deno): add GPUPipelineErrorInit{,Init,Reason}
1 parent c5e460f commit 7b3da03

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

deno_webgpu/error.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ use std::fmt::Formatter;
55
use std::sync::Mutex;
66
use std::sync::OnceLock;
77

8+
use deno_core::anyhow;
89
use deno_core::cppgc::make_cppgc_object;
910
use deno_core::v8;
1011

12+
use deno_core::op2;
13+
use deno_core::webidl::WebIdlInterfaceConverter;
14+
use deno_core::GarbageCollected;
1115
use deno_core::JsRuntime;
1216
use deno_core::V8TaskSpawner;
17+
use deno_core::WebIDL;
1318
use wgpu_core::binding_model::CreateBindGroupError;
1419
use wgpu_core::binding_model::CreateBindGroupLayoutError;
1520
use wgpu_core::binding_model::CreatePipelineLayoutError;
@@ -379,3 +384,59 @@ pub enum GPUGenericError {
379384
#[error("Illegal constructor")]
380385
InvalidConstructor,
381386
}
387+
388+
#[derive(Debug, thiserror::Error, deno_error::JsError)]
389+
#[property("code" = 0)]
390+
#[property("message" = self.to_string())]
391+
#[property("name" = self.get_name().to_str().unwrap())]
392+
// TODO: Could we just return the type directly?
393+
#[property("reason" = self.reason.as_str().to_string())]
394+
// TODO: use `DOMException`
395+
#[class(generic)]
396+
#[error("{reason:?} error: {}", fmt_err(self.inner.as_ref()))]
397+
pub struct GPUPipelineError {
398+
pub reason: GPUPipelineErrorReason,
399+
pub(crate) inner: anyhow::Error,
400+
}
401+
402+
#[derive(WebIDL)]
403+
#[webidl(dictionary)]
404+
pub struct GPUPipelineErrorInit {
405+
pub reason: GPUPipelineErrorReason,
406+
}
407+
408+
#[derive(WebIDL, Clone, Copy, Debug)]
409+
#[webidl(enum)]
410+
pub enum GPUPipelineErrorReason {
411+
Validation,
412+
Internal,
413+
}
414+
415+
impl GPUPipelineError {
416+
pub fn new(options: GPUPipelineErrorInit, inner: anyhow::Error) -> Self {
417+
let GPUPipelineErrorInit { reason } = options;
418+
Self { inner, reason }
419+
}
420+
}
421+
422+
#[op2]
423+
impl GPUPipelineError {
424+
#[constructor]
425+
#[cppgc]
426+
fn constructor(
427+
#[webidl(default = "")] message: String,
428+
#[webidl] options: GPUPipelineErrorInit,
429+
) -> GPUPipelineError {
430+
GPUPipelineError::new(options, anyhow::Error::msg(message))
431+
}
432+
}
433+
434+
impl WebIdlInterfaceConverter for GPUPipelineError {
435+
const NAME: &'static str = "GPUPipelineError";
436+
}
437+
438+
impl GarbageCollected for GPUPipelineError {
439+
fn get_name(&self) -> &'static std::ffi::CStr {
440+
c"GPUPipelineError"
441+
}
442+
}

0 commit comments

Comments
 (0)