refactor: fix error module after rebase and reduce usage of the eyre! macro

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-12-31 23:50:17 +01:00
parent 1fcb54c84c
commit 054109d9c7
6 changed files with 29 additions and 32 deletions

View File

@@ -8,7 +8,6 @@ use stardust_xr::{
FlexSerializeError, FlexSerializeError,
}, },
}; };
use stereokit_rust::StereoKitError;
use thiserror::Error; use thiserror::Error;
pub type Result<T, E = ServerError> = std::result::Result<T, E>; pub type Result<T, E = ServerError> = std::result::Result<T, E>;
@@ -19,6 +18,8 @@ pub enum ServerError {
NoClient, NoClient,
#[error("Messenger does not exist for this node")] #[error("Messenger does not exist for this node")]
NoMessenger, NoMessenger,
#[error("Could not find resource")]
NoResource,
#[error("Messenger error: {0}")] #[error("Messenger error: {0}")]
MessengerError(#[from] MessengerError), MessengerError(#[from] MessengerError),
#[error("Remote method error: {0}")] #[error("Remote method error: {0}")]
@@ -29,8 +30,6 @@ pub enum ServerError {
DeserializationError(#[from] DeserializationError), DeserializationError(#[from] DeserializationError),
#[error("Reader error: {0}")] #[error("Reader error: {0}")]
ReaderError(#[from] ReaderError), ReaderError(#[from] ReaderError),
#[error("StereoKit error: {0}")]
StereoKitError(#[from] StereoKitError),
#[error("Aspect {} does not exist for node", 0.to_string())] #[error("Aspect {} does not exist for node", 0.to_string())]
NoAspect(TypeId), NoAspect(TypeId),
#[error("{0}")] #[error("{0}")]

View File

@@ -1,7 +1,7 @@
use super::{Aspect, AspectIdentifier, Node}; use super::{Aspect, AspectIdentifier, Node};
use crate::core::client::Client; use crate::core::client::Client;
use crate::core::destroy_queue; use crate::core::destroy_queue;
use crate::core::error::Result; use crate::core::error::{Result, ServerError};
use crate::core::registry::Registry; use crate::core::registry::Registry;
use crate::core::resource::get_resource_file; use crate::core::resource::get_resource_file;
use crate::nodes::spatial::{Spatial, Transform, SPATIAL_ASPECT_ALIAS_INFO}; use crate::nodes::spatial::{Spatial, Transform, SPATIAL_ASPECT_ALIAS_INFO};
@@ -23,10 +23,10 @@ pub struct StardustSoundPlugin;
impl Plugin for StardustSoundPlugin { impl Plugin for StardustSoundPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
let (tx, rx) = crossbeam_channel::unbounded(); let (tx, rx) = crossbeam_channel::unbounded();
SOUND_EVENT_SENDER.set(tx); _ = SOUND_EVENT_SENDER.set(tx);
app.insert_resource(SoundEventReader(rx)); app.insert_resource(SoundEventReader(rx));
let (tx, rx) = crossbeam_channel::unbounded(); let (tx, rx) = crossbeam_channel::unbounded();
SPAWN_SOUND_SENDER.set(tx); _ = SPAWN_SOUND_SENDER.set(tx);
app.insert_resource(SpawnSoundReader(rx)); app.insert_resource(SpawnSoundReader(rx));
app.add_systems(PostUpdate, update_sound_state); app.add_systems(PostUpdate, update_sound_state);
app.add_systems(PreUpdate, spawn_sounds); app.add_systems(PreUpdate, spawn_sounds);
@@ -108,10 +108,10 @@ impl Sound {
pub fn add_to(node: &Arc<Node>, resource_id: ResourceID) -> Result<Arc<Sound>> { pub fn add_to(node: &Arc<Node>, resource_id: ResourceID) -> Result<Arc<Sound>> {
let pending_audio_path = get_resource_file( let pending_audio_path = get_resource_file(
&resource_id, &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")], &[OsStr::new("wav"), OsStr::new("mp3")],
) )
.ok_or_else(|| eyre!("Resource not found"))?; .ok_or(ServerError::NoResource)?;
let sound = Sound { let sound = Sound {
space: node.get_aspect::<Spatial>().unwrap().clone(), space: node.get_aspect::<Spatial>().unwrap().clone(),
volume: 1.0, volume: 1.0,

View File

@@ -1,4 +1,5 @@
use super::{Line, LinesAspect}; use super::{Line, LinesAspect};
use crate::core::error::Result;
use crate::{ use crate::{
bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation}, bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation},
core::{client::Client, registry::Registry}, core::{client::Client, registry::Registry},
@@ -14,7 +15,6 @@ use bevy::{
AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With, AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With,
}, },
}; };
use color_eyre::eyre::Result;
use glam::{Vec3, Vec3A}; use glam::{Vec3, Vec3A};
use parking_lot::Mutex; use parking_lot::Mutex;
use prisma::Lerp; use prisma::Lerp;

View File

@@ -10,7 +10,11 @@ use super::{
spatial::{Spatial, Transform}, spatial::{Spatial, Transform},
Aspect, AspectIdentifier, Node, 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 crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO;
use color_eyre::eyre::eyre; use color_eyre::eyre::eyre;
use model::ModelPart; use model::ModelPart;
@@ -51,7 +55,7 @@ impl Aspect for Text {
impl InterfaceAspect for Interface { impl InterfaceAspect for Interface {
fn set_sky_tex(_node: Arc<Node>, calling_client: Arc<Client>, tex: ResourceID) -> Result<()> { fn set_sky_tex(_node: Arc<Node>, calling_client: Arc<Client>, tex: ResourceID) -> Result<()> {
let resource_path = get_resource_file(&tex, &calling_client, &[OsStr::new("hdr")]) 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); QUEUED_SKYTEX.lock().replace(resource_path);
Ok(()) Ok(())
} }
@@ -62,7 +66,7 @@ impl InterfaceAspect for Interface {
light: ResourceID, light: ResourceID,
) -> Result<()> { ) -> Result<()> {
let resource_path = get_resource_file(&light, &calling_client, &[OsStr::new("hdr")]) 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); QUEUED_SKYLIGHT.lock().replace(resource_path);
Ok(()) Ok(())
} }

View File

@@ -1,44 +1,36 @@
use super::{MaterialParameter, ModelAspect, ModelPartAspect, MODEL_PART_ASPECT_ALIAS_INFO}; use super::{MaterialParameter, ModelAspect, ModelPartAspect, MODEL_PART_ASPECT_ALIAS_INFO};
use crate::bail; use crate::bevy_plugin::DESTROY_ENTITY;
use crate::bevy_plugin::{MainWorldEntity, DESTROY_ENTITY};
use crate::core::client::Client; use crate::core::client::Client;
use crate::core::error::Result; use crate::core::error::{Result, ServerError};
use crate::core::registry::Registry; use crate::core::registry::Registry;
use crate::core::resource::get_resource_file; use crate::core::resource::get_resource_file;
use crate::nodes::alias::{Alias, AliasList}; use crate::nodes::alias::{Alias, AliasList};
use crate::nodes::spatial::Spatial; use crate::nodes::spatial::Spatial;
use crate::nodes::Node; use crate::nodes::Node;
use crate::{DefaultMaterial, TOKIO}; use crate::DefaultMaterial;
use bevy::app::{Plugin, PostUpdate, PreUpdate, Update}; use bevy::app::{Plugin, PostUpdate, PreUpdate, Update};
use bevy::asset::{AssetServer, Assets}; use bevy::asset::{AssetServer, Assets};
use bevy::color::{Alpha, Color, LinearRgba, Srgba}; use bevy::color::{Color, LinearRgba};
use bevy::core::Name; use bevy::core::Name;
use bevy::gltf::GltfAssetLabel; use bevy::gltf::GltfAssetLabel;
use bevy::math::bounding::Aabb3d; use bevy::math::bounding::Aabb3d;
use bevy::pbr::MeshMaterial3d; use bevy::pbr::MeshMaterial3d;
use bevy::prelude::AlphaMode;
use bevy::prelude::{ use bevy::prelude::{
BuildChildrenTransformExt, Children, Commands, Component, Deref, Entity, Has, BuildChildrenTransformExt, Children, Commands, Component, Deref, Entity, Has,
HierarchyQueryExt, Mesh3d, Parent, Query, Res, ResMut, Resource, Transform, Visibility, With, HierarchyQueryExt, Parent, Query, Res, ResMut, Resource, Transform, Visibility, With, Without,
Without,
}; };
use bevy::reflect::{GetField, PartialReflect, Reflect}; use bevy::reflect::GetField;
use bevy::render::primitives::Aabb; use bevy::render::primitives::Aabb;
use bevy::scene::SceneRoot; use bevy::scene::SceneRoot;
use color_eyre::eyre::eyre;
use bevy::tasks::futures_lite::FutureExt;
use glam::{Mat4, Vec2, Vec3}; use glam::{Mat4, Vec2, Vec3};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use stardust_xr::values::ResourceID; use stardust_xr::values::ResourceID;
use tokio::sync::Notify;
use tracing::{error, info, warn}; use tracing::{error, info, warn};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::future::IntoFuture; use std::path::PathBuf;
use std::ops::Deref;
use std::path::{self, PathBuf};
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
static MODEL_REGISTRY: Registry<Model> = Registry::new(); static MODEL_REGISTRY: Registry<Model> = Registry::new();
@@ -399,10 +391,10 @@ impl Model {
pub fn add_to(node: &Arc<Node>, resource_id: ResourceID) -> Result<Arc<Model>> { pub fn add_to(node: &Arc<Node>, resource_id: ResourceID) -> Result<Arc<Model>> {
let pending_model_path = get_resource_file( let pending_model_path = get_resource_file(
&resource_id, &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")], &[OsStr::new("glb"), OsStr::new("gltf")],
) )
.ok_or_else(|| eyre!("Resource not found"))?; .ok_or(ServerError::NoResource)?;
let model = Arc::new(Model { let model = Arc::new(Model {
space: node.get_aspect::<Spatial>().unwrap().clone(), space: node.get_aspect::<Spatial>().unwrap().clone(),

View File

@@ -1,7 +1,10 @@
use crate::{ use crate::{
bevy_plugin::convert_linear_rgba, bevy_plugin::convert_linear_rgba,
core::{ core::{
client::Client, destroy_queue, error::Result, registry::Registry, client::Client,
destroy_queue,
error::{Result, ServerError},
registry::Registry,
resource::get_resource_file, resource::get_resource_file,
}, },
nodes::{spatial::Spatial, Aspect, Node}, nodes::{spatial::Spatial, Aspect, Node},
@@ -24,7 +27,6 @@ use bevy::{
text::{cosmic_text::Align, JustifyText, TextColor, TextFont}, text::{cosmic_text::Align, JustifyText, TextColor, TextFont},
ui::{AlignItems, BackgroundColor, FlexDirection, JustifyContent, TargetCamera, Val}, ui::{AlignItems, BackgroundColor, FlexDirection, JustifyContent, TargetCamera, Val},
}; };
use color_eyre::eyre::eyre;
use glam::{vec3, Mat4, Vec2, Vec3}; use glam::{vec3, Mat4, Vec2, Vec3};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -204,7 +206,7 @@ pub struct Text {
} }
impl Text { impl Text {
pub fn add_to(node: &Arc<Node>, text: String, style: TextStyle) -> Result<Arc<Text>> { pub fn add_to(node: &Arc<Node>, text: String, style: TextStyle) -> Result<Arc<Text>> {
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 { let text = TEXT_REGISTRY.add(Text {
space: node.get_aspect::<Spatial>().unwrap().clone(), space: node.get_aspect::<Spatial>().unwrap().clone(),
font_path: style.font.as_ref().and_then(|res| { font_path: style.font.as_ref().and_then(|res| {