remove PrettyError

This commit is contained in:
teoxoy 2024-06-28 19:35:15 +02:00 committed by Teodor Tanasoaia
parent 08b8e96c40
commit 3547138716
11 changed files with 9 additions and 111 deletions

View File

@ -2,7 +2,6 @@ use crate::{
device::{
bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT,
},
error::PrettyError,
hal_api::HalApi,
id::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId},
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
@ -191,8 +190,6 @@ pub enum CreateBindGroupError {
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
}
impl PrettyError for CreateBindGroupError {}
#[derive(Clone, Debug, Error)]
pub enum BindingZone {
#[error("Stage {0:?}")]
@ -555,8 +552,6 @@ pub enum CreatePipelineLayoutError {
TooManyGroups { actual: usize, max: usize },
}
impl PrettyError for CreatePipelineLayoutError {}
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum PushConstantUploadError {

View File

@ -89,7 +89,6 @@ use crate::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
SHADER_STAGE_COUNT,
},
error::PrettyError,
hal_api::HalApi,
hub::Hub,
id,
@ -948,7 +947,6 @@ pub enum ExecutionError {
#[error("Using {0} in a render bundle is not implemented")]
Unimplemented(&'static str),
}
impl PrettyError for ExecutionError {}
pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor<Label<'a>>;
@ -1593,7 +1591,6 @@ impl RenderBundleError {
}
}
}
impl PrettyError for RenderBundleError {}
impl<T, E> MapPassErr<T, RenderBundleError> for Result<T, E>
where

View File

@ -12,7 +12,6 @@ use crate::{
PassErrorScope, PassTimestampWrites, QueryUseError, StateChange,
},
device::{Device, DeviceError, MissingDownlevelFlags, MissingFeatures},
error::PrettyError,
global::Global,
hal_api::HalApi,
hal_label, id,
@ -182,8 +181,6 @@ pub enum ComputePassErrorInner {
PassEnded,
}
impl PrettyError for ComputePassErrorInner {}
/// Error encountered when performing a compute pass.
#[derive(Clone, Debug, Error)]
#[error("{scope}")]
@ -192,7 +189,6 @@ pub struct ComputePassError {
#[source]
pub(super) inner: ComputePassErrorInner,
}
impl PrettyError for ComputePassError {}
impl<T, E> MapPassErr<T, ComputePassError> for Result<T, E>
where

View File

@ -109,7 +109,6 @@ pub enum RenderCommandError {
#[error("Support for {0} is not implemented yet")]
Unimplemented(&'static str),
}
impl crate::error::PrettyError for RenderCommandError {}
#[derive(Clone, Copy, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

View File

@ -30,7 +30,6 @@ pub use timestamp_writes::PassTimestampWrites;
use self::memory_init::CommandBufferTextureMemoryActions;
use crate::device::{Device, DeviceError};
use crate::error::PrettyError;
use crate::hub::Hub;
use crate::lock::{rank, Mutex};
use crate::snatch::SnatchGuard;
@ -608,8 +607,6 @@ pub enum CommandEncoderError {
InvalidOcclusionQuerySetId(id::QuerySetId),
}
impl PrettyError for CommandEncoderError {}
impl Global {
pub fn command_encoder_finish<A: HalApi>(
&self,
@ -910,5 +907,3 @@ pub enum PassErrorScope {
#[error("In a insert_debug_marker command")]
InsertDebugMarker,
}
impl PrettyError for PassErrorScope {}

View File

@ -113,8 +113,6 @@ pub enum QueryError {
InvalidQuerySetId(id::QuerySetId),
}
impl crate::error::PrettyError for QueryError {}
/// Error encountered while trying to use queries
#[derive(Clone, Debug, Error)]
#[non_exhaustive]

View File

@ -20,7 +20,6 @@ use crate::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, MissingFeatures,
RenderPassCompatibilityError, RenderPassContext,
},
error::PrettyError,
global::Global,
hal_api::HalApi,
hal_label, id,
@ -710,8 +709,6 @@ pub enum RenderPassErrorInner {
PassEnded,
}
impl PrettyError for RenderPassErrorInner {}
impl From<MissingBufferUsageError> for RenderPassErrorInner {
fn from(error: MissingBufferUsageError) -> Self {
Self::RenderCommand(error.into())
@ -738,7 +735,6 @@ pub struct RenderPassError {
#[source]
pub(super) inner: RenderPassErrorInner,
}
impl PrettyError for RenderPassError {}
impl<T, E> MapPassErr<T, RenderPassError> for Result<T, E>
where

View File

@ -5,7 +5,6 @@ use crate::{
command::{clear_texture, CommandBuffer, CommandEncoderError},
conv,
device::{Device, DeviceError, MissingDownlevelFlags},
error::PrettyError,
global::Global,
hal_api::HalApi,
id::{BufferId, CommandEncoderId, TextureId},
@ -143,8 +142,6 @@ pub enum TransferError {
InvalidMipLevel { requested: u32, count: u32 },
}
impl PrettyError for TransferError {}
/// Error encountered while attempting to do a copy on a command encoder.
#[derive(Clone, Debug, Error)]
#[non_exhaustive]

View File

@ -3,76 +3,6 @@ use std::{error::Error, sync::Arc};
use thiserror::Error;
pub struct ErrorFormatter<'a> {
writer: &'a mut dyn fmt::Write,
}
impl<'a> ErrorFormatter<'a> {
pub fn error(&mut self, err: &dyn Error) {
writeln!(self.writer, " {err}").expect("Error formatting error");
}
}
pub trait PrettyError: Error + Sized {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
fmt.error(self);
}
}
pub fn format_pretty_any(writer: &mut dyn fmt::Write, error: &(dyn Error + 'static)) {
let mut fmt = ErrorFormatter { writer };
if let Some(pretty_err) = error.downcast_ref::<ContextError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::RenderCommandError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::binding_model::CreateBindGroupError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) =
error.downcast_ref::<crate::binding_model::CreatePipelineLayoutError>()
{
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::ExecutionError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::RenderPassErrorInner>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::RenderPassError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::ComputePassErrorInner>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::ComputePassError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::RenderBundleError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::TransferError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::PassErrorScope>() {
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::track::ResourceUsageCompatibilityError>()
{
return pretty_err.fmt_pretty(&mut fmt);
}
if let Some(pretty_err) = error.downcast_ref::<crate::command::QueryError>() {
return pretty_err.fmt_pretty(&mut fmt);
}
// default
fmt.error(error)
}
#[derive(Debug, Error)]
#[error(
"In {fn_ident}{}{}{}",
@ -90,8 +20,6 @@ pub struct ContextError {
pub label: String,
}
impl PrettyError for ContextError {}
/// Don't use this error type with thiserror's #[error(transparent)]
#[derive(Clone)]
pub struct MultiError {

View File

@ -385,8 +385,6 @@ impl ResourceUsageCompatibilityError {
}
}
impl crate::error::PrettyError for ResourceUsageCompatibilityError {}
/// Pretty print helper that shows helpful descriptions of a conflicting usage.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InvalidUse<T> {

View File

@ -313,18 +313,17 @@ impl ContextWgpuCore {
}
fn format_error(&self, err: &(impl Error + 'static)) -> String {
let mut err_descs = vec![];
let mut level = 0;
let mut output = String::new();
let mut level = 1;
fn print_tree(err_descs: &mut Vec<String>, level: &mut usize, e: &(dyn Error + 'static)) {
let mut print = |e| {
let mut err_str = " ".repeat(*level * 2);
wgc::error::format_pretty_any(&mut err_str, e);
err_descs.push(err_str);
fn print_tree(output: &mut String, level: &mut usize, e: &(dyn Error + 'static)) {
let mut print = |e: &(dyn Error + 'static)| {
use std::fmt::Write;
writeln!(output, "{}{}", " ".repeat(*level * 2), e).unwrap();
if let Some(e) = e.source() {
*level += 1;
print_tree(err_descs, level, e);
print_tree(output, level, e);
*level -= 1;
}
};
@ -337,9 +336,9 @@ impl ContextWgpuCore {
}
}
print_tree(&mut err_descs, &mut level, err);
print_tree(&mut output, &mut level, err);
format!("Validation Error\n\nCaused by:\n{}", err_descs.join(""))
format!("Validation Error\n\nCaused by:\n{}", output)
}
}