wgpu_types/
error.rs

1//! Shared types for WebGPU errors. See also:
2//! <https://gpuweb.github.io/gpuweb/#errors-and-debugging>
3
4/// A classification of WebGPU error for implementers of the WebGPU API to use in their own error
5/// layer(s).
6///
7/// Strongly correlates to the [`GPUError`] and [`GPUErrorFilter`] types in the WebGPU API, with an
8/// additional [`Self::DeviceLost`] variant.
9///
10/// [`GPUError`]: https://gpuweb.github.io/gpuweb/#gpuerror
11/// [`GPUErrorFilter`]: https://gpuweb.github.io/gpuweb/#enumdef-gpuerrorfilter
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
14pub enum ErrorType {
15    /// A [`GPUInternalError`].
16    ///
17    /// [`GPUInternalError`]: https://gpuweb.github.io/gpuweb/#gpuinternalerror
18    Internal,
19    /// A [`GPUOutOfMemoryError`].
20    ///
21    /// [`GPUOutOfMemoryError`]: https://gpuweb.github.io/gpuweb/#gpuoutofmemoryerror
22    OutOfMemory,
23    /// A [`GPUValidationError`].
24    ///
25    /// [`GPUValidationError`]: https://gpuweb.github.io/gpuweb/#gpuvalidationerror
26    Validation,
27    /// Indicates that device loss occurred. In JavaScript, this means the [`GPUDevice.lost`]
28    /// property should be `resolve`d.
29    ///
30    /// [`GPUDevice.lost`]: https://www.w3.org/TR/webgpu/#dom-gpudevice-lost
31    DeviceLost,
32}
33
34/// A trait for querying the [`ErrorType`] classification of an error.
35///
36/// This is intended to be used as a convenience by implementations of WebGPU to classify errors
37/// returned by [`wgpu_core`](crate).
38pub trait WebGpuError: core::error::Error + 'static {
39    /// Determine the classification of this error as a WebGPU [`ErrorType`].
40    fn webgpu_error_type(&self) -> ErrorType;
41}