From 054109d9c75e9a1af47a9ad4ce1f1315ed2b2ed4 Mon Sep 17 00:00:00 2001 From: Schmarni Date: Tue, 31 Dec 2024 23:50:17 +0100 Subject: [PATCH] refactor: fix error module after rebase and reduce usage of the eyre! macro Signed-off-by: Schmarni --- src/core/error.rs | 5 ++--- src/nodes/audio.rs | 10 +++++----- src/nodes/drawable/lines.rs | 2 +- src/nodes/drawable/mod.rs | 10 +++++++--- src/nodes/drawable/model.rs | 26 +++++++++----------------- src/nodes/drawable/text.rs | 8 +++++--- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/core/error.rs b/src/core/error.rs index 6dbe502..3f189dc 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -8,7 +8,6 @@ use stardust_xr::{ FlexSerializeError, }, }; -use stereokit_rust::StereoKitError; use thiserror::Error; pub type Result = std::result::Result; @@ -19,6 +18,8 @@ pub enum ServerError { NoClient, #[error("Messenger does not exist for this node")] NoMessenger, + #[error("Could not find resource")] + NoResource, #[error("Messenger error: {0}")] MessengerError(#[from] MessengerError), #[error("Remote method error: {0}")] @@ -29,8 +30,6 @@ pub enum ServerError { DeserializationError(#[from] DeserializationError), #[error("Reader error: {0}")] ReaderError(#[from] ReaderError), - #[error("StereoKit error: {0}")] - StereoKitError(#[from] StereoKitError), #[error("Aspect {} does not exist for node", 0.to_string())] NoAspect(TypeId), #[error("{0}")] diff --git a/src/nodes/audio.rs b/src/nodes/audio.rs index f3b36fe..990b4c3 100644 --- a/src/nodes/audio.rs +++ b/src/nodes/audio.rs @@ -1,7 +1,7 @@ use super::{Aspect, AspectIdentifier, Node}; use crate::core::client::Client; use crate::core::destroy_queue; -use crate::core::error::Result; +use crate::core::error::{Result, ServerError}; use crate::core::registry::Registry; use crate::core::resource::get_resource_file; use crate::nodes::spatial::{Spatial, Transform, SPATIAL_ASPECT_ALIAS_INFO}; @@ -23,10 +23,10 @@ pub struct StardustSoundPlugin; impl Plugin for StardustSoundPlugin { fn build(&self, app: &mut App) { let (tx, rx) = crossbeam_channel::unbounded(); - SOUND_EVENT_SENDER.set(tx); + _ = SOUND_EVENT_SENDER.set(tx); app.insert_resource(SoundEventReader(rx)); let (tx, rx) = crossbeam_channel::unbounded(); - SPAWN_SOUND_SENDER.set(tx); + _ = SPAWN_SOUND_SENDER.set(tx); app.insert_resource(SpawnSoundReader(rx)); app.add_systems(PostUpdate, update_sound_state); app.add_systems(PreUpdate, spawn_sounds); @@ -108,10 +108,10 @@ impl Sound { pub fn add_to(node: &Arc, resource_id: ResourceID) -> Result> { let pending_audio_path = get_resource_file( &resource_id, - &*node.get_client().ok_or_else(|| eyre!("Client not found"))?, + &*node.get_client().ok_or(ServerError::NoClient)?, &[OsStr::new("wav"), OsStr::new("mp3")], ) - .ok_or_else(|| eyre!("Resource not found"))?; + .ok_or(ServerError::NoResource)?; let sound = Sound { space: node.get_aspect::().unwrap().clone(), volume: 1.0, diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index 82421ba..9e1800a 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -1,4 +1,5 @@ use super::{Line, LinesAspect}; +use crate::core::error::Result; use crate::{ bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation}, core::{client::Client, registry::Registry}, @@ -14,7 +15,6 @@ use bevy::{ AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With, }, }; -use color_eyre::eyre::Result; use glam::{Vec3, Vec3A}; use parking_lot::Mutex; use prisma::Lerp; diff --git a/src/nodes/drawable/mod.rs b/src/nodes/drawable/mod.rs index 04c6434..d48501c 100644 --- a/src/nodes/drawable/mod.rs +++ b/src/nodes/drawable/mod.rs @@ -10,7 +10,11 @@ use super::{ spatial::{Spatial, Transform}, Aspect, AspectIdentifier, Node, }; -use crate::core::{client::Client, error::Result, resource::get_resource_file}; +use crate::core::{ + client::Client, + error::{Result, ServerError}, + resource::get_resource_file, +}; use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO; use color_eyre::eyre::eyre; use model::ModelPart; @@ -51,7 +55,7 @@ impl Aspect for Text { impl InterfaceAspect for Interface { fn set_sky_tex(_node: Arc, calling_client: Arc, tex: ResourceID) -> Result<()> { let resource_path = get_resource_file(&tex, &calling_client, &[OsStr::new("hdr")]) - .ok_or(eyre!("Could not find resource"))?; + .ok_or(ServerError::NoResource)?; QUEUED_SKYTEX.lock().replace(resource_path); Ok(()) } @@ -62,7 +66,7 @@ impl InterfaceAspect for Interface { light: ResourceID, ) -> Result<()> { let resource_path = get_resource_file(&light, &calling_client, &[OsStr::new("hdr")]) - .ok_or(eyre!("Could not find resource"))?; + .ok_or(ServerError::NoResource)?; QUEUED_SKYLIGHT.lock().replace(resource_path); Ok(()) } diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index 55f8a6f..362e4dd 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -1,44 +1,36 @@ use super::{MaterialParameter, ModelAspect, ModelPartAspect, MODEL_PART_ASPECT_ALIAS_INFO}; -use crate::bail; -use crate::bevy_plugin::{MainWorldEntity, DESTROY_ENTITY}; +use crate::bevy_plugin::DESTROY_ENTITY; use crate::core::client::Client; -use crate::core::error::Result; +use crate::core::error::{Result, ServerError}; use crate::core::registry::Registry; use crate::core::resource::get_resource_file; use crate::nodes::alias::{Alias, AliasList}; use crate::nodes::spatial::Spatial; use crate::nodes::Node; -use crate::{DefaultMaterial, TOKIO}; +use crate::DefaultMaterial; use bevy::app::{Plugin, PostUpdate, PreUpdate, Update}; use bevy::asset::{AssetServer, Assets}; -use bevy::color::{Alpha, Color, LinearRgba, Srgba}; +use bevy::color::{Color, LinearRgba}; use bevy::core::Name; use bevy::gltf::GltfAssetLabel; use bevy::math::bounding::Aabb3d; use bevy::pbr::MeshMaterial3d; -use bevy::prelude::AlphaMode; use bevy::prelude::{ BuildChildrenTransformExt, Children, Commands, Component, Deref, Entity, Has, - HierarchyQueryExt, Mesh3d, Parent, Query, Res, ResMut, Resource, Transform, Visibility, With, - Without, + HierarchyQueryExt, Parent, Query, Res, ResMut, Resource, Transform, Visibility, With, Without, }; -use bevy::reflect::{GetField, PartialReflect, Reflect}; +use bevy::reflect::GetField; use bevy::render::primitives::Aabb; use bevy::scene::SceneRoot; -use color_eyre::eyre::eyre; -use bevy::tasks::futures_lite::FutureExt; use glam::{Mat4, Vec2, Vec3}; use once_cell::sync::OnceCell; use parking_lot::Mutex; use rustc_hash::FxHashMap; use stardust_xr::values::ResourceID; -use tokio::sync::Notify; use tracing::{error, info, warn}; use std::ffi::OsStr; -use std::future::IntoFuture; -use std::ops::Deref; -use std::path::{self, PathBuf}; +use std::path::PathBuf; use std::sync::{Arc, Weak}; static MODEL_REGISTRY: Registry = Registry::new(); @@ -399,10 +391,10 @@ impl Model { pub fn add_to(node: &Arc, resource_id: ResourceID) -> Result> { let pending_model_path = get_resource_file( &resource_id, - &*node.get_client().ok_or_else(|| eyre!("Client not found"))?, + &*node.get_client().ok_or(ServerError::NoClient)?, &[OsStr::new("glb"), OsStr::new("gltf")], ) - .ok_or_else(|| eyre!("Resource not found"))?; + .ok_or(ServerError::NoResource)?; let model = Arc::new(Model { space: node.get_aspect::().unwrap().clone(), diff --git a/src/nodes/drawable/text.rs b/src/nodes/drawable/text.rs index c207df2..9bd75d8 100644 --- a/src/nodes/drawable/text.rs +++ b/src/nodes/drawable/text.rs @@ -1,7 +1,10 @@ use crate::{ bevy_plugin::convert_linear_rgba, core::{ - client::Client, destroy_queue, error::Result, registry::Registry, + client::Client, + destroy_queue, + error::{Result, ServerError}, + registry::Registry, resource::get_resource_file, }, nodes::{spatial::Spatial, Aspect, Node}, @@ -24,7 +27,6 @@ use bevy::{ text::{cosmic_text::Align, JustifyText, TextColor, TextFont}, ui::{AlignItems, BackgroundColor, FlexDirection, JustifyContent, TargetCamera, Val}, }; -use color_eyre::eyre::eyre; use glam::{vec3, Mat4, Vec2, Vec3}; use once_cell::sync::OnceCell; use parking_lot::Mutex; @@ -204,7 +206,7 @@ pub struct Text { } impl Text { pub fn add_to(node: &Arc, text: String, style: TextStyle) -> Result> { - let client = node.get_client().ok_or_else(|| eyre!("Client not found"))?; + let client = node.get_client().ok_or(ServerError::NoClient)?; let text = TEXT_REGISTRY.add(Text { space: node.get_aspect::().unwrap().clone(), font_path: style.font.as_ref().and_then(|res| {