From fc91fbe24cebaf4fa4ac5b81e6c1c9f9d56f293e Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 29 Dec 2024 18:14:54 -0800 Subject: [PATCH 1/4] fix(ci): update to use v4 of stuff --- .github/workflows/build.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a58c914..07d6cca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Build on: push: branches: - - '*' + - "*" jobs: build_and_package: @@ -11,7 +11,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install runtime dependencies run: sudo apt install -y --no-install-recommends libxkbcommon-dev libstdc++6 libopenxr-dev libx11-dev libxfixes-dev libgl1-mesa-dev libegl1-mesa-dev libgbm-dev libfontconfig-dev libjsoncpp-dev libxcb1-dev libglx-dev libxcb-glx0-dev libdrm-dev libwayland-dev libfreetype-dev libpng-dev @@ -27,12 +27,11 @@ jobs: - name: Build server run: cargo build --release - - name: Install appimagetool run: | - wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool; \ - chmod +x /usr/local/bin/appimagetool; \ - sed -i 's|AI\x02|\x00\x00\x00|' /usr/local/bin/appimagetool + wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool; \ + chmod +x /usr/local/bin/appimagetool; \ + sed -i 's|AI\x02|\x00\x00\x00|' /usr/local/bin/appimagetool - name: Install cargo-appimage run: cargo install cargo-appimage @@ -40,7 +39,7 @@ jobs: run: cargo appimage - name: Upload AppImage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: appimage - path: '*.AppImage' \ No newline at end of file + path: "*.AppImage" -- 2.49.1 From 212ceb7a6db45d6364008c1c929b0a61bd807c2f Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 29 Dec 2024 18:35:13 -0800 Subject: [PATCH 2/4] fix(ci): appimage path --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07d6cca..0e15220 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,4 +42,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: appimage - path: "*.AppImage" + path: "target/appimage/stardust-xr-server.AppImage" -- 2.49.1 From 0adde690491c43e625beaab65f5fee8ec25c997a Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 29 Dec 2024 19:16:19 -0800 Subject: [PATCH 3/4] fix(ci): libfuse2 for appimages --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e15220..8327f56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: run: sudo apt install -y --no-install-recommends libxkbcommon-dev libstdc++6 libopenxr-dev libx11-dev libxfixes-dev libgl1-mesa-dev libegl1-mesa-dev libgbm-dev libfontconfig-dev libjsoncpp-dev libxcb1-dev libglx-dev libxcb-glx0-dev libdrm-dev libwayland-dev libfreetype-dev libpng-dev - name: Install build dependencies - run: sudo apt install -y --no-install-recommends cmake ninja-build + run: sudo apt install -y --no-install-recommends cmake ninja-build libfuse2 - name: Set up Rust uses: actions-rs/toolchain@v1 -- 2.49.1 From d434af8b84f0a17b7477279b9f9aecade38573d2 Mon Sep 17 00:00:00 2001 From: ash lea Date: Mon, 30 Dec 2024 15:28:39 -0500 Subject: [PATCH 4/4] start to convert ad-hoc errors to explicit types --- Cargo.lock | 13 ++++--- Cargo.toml | 1 + codegen/src/lib.rs | 22 +++++------ src/core/error.rs | 75 +++++++++++++++++++++++++++++++++++++ src/core/mod.rs | 1 + src/core/scenegraph.rs | 8 ++-- src/nodes/alias.rs | 3 +- src/nodes/audio.rs | 3 +- src/nodes/drawable/lines.rs | 3 +- src/nodes/drawable/mod.rs | 8 ++-- src/nodes/drawable/model.rs | 8 ++-- src/nodes/drawable/text.rs | 25 +++++++------ src/nodes/fields.rs | 7 ++-- src/nodes/input/method.rs | 3 +- src/nodes/input/mod.rs | 2 +- src/nodes/items/camera.rs | 7 ++-- src/nodes/items/mod.rs | 3 +- src/nodes/items/panel.rs | 5 ++- src/nodes/mod.rs | 14 +++---- src/nodes/root.rs | 5 ++- src/nodes/spatial/mod.rs | 12 +++--- src/nodes/spatial/zone.rs | 3 +- src/wayland/xdg_shell.rs | 13 ++++--- 23 files changed, 166 insertions(+), 78 deletions(-) create mode 100644 src/core/error.rs diff --git a/Cargo.lock b/Cargo.lock index 8059e47..ab6942a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2720,6 +2720,7 @@ dependencies = [ "stardust-xr", "stardust-xr-server-codegen", "stereokit-rust", + "thiserror 2.0.9", "tokio", "toml", "tracing", @@ -2771,7 +2772,7 @@ dependencies = [ "ndk-sys", "openxr-sys", "stereokit-macros", - "thiserror 2.0.3", + "thiserror 2.0.9", ] [[package]] @@ -2881,11 +2882,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.9", ] [[package]] @@ -2901,9 +2902,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 6d9f166..fc9e779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,6 +96,7 @@ xkbcommon-rs = "0.1.0" # wayland wayland-backend = { version = "0.3.7", optional = true, default-features = false } wayland-scanner = { version = "0.31.4", optional = true } +thiserror = "2.0.9" [dependencies.smithay] # git = "https://github.com/technobaboo/smithay.git" diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 1357644..b91087d 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -75,7 +75,7 @@ fn codegen_protocol(protocol: &'static str) -> proc_macro::TokenStream { impl crate::nodes::Aspect for Interface { impl_aspect_for_interface_aspect!{} } - pub fn create_interface(client: &std::sync::Arc) -> color_eyre::eyre::Result<()>{ + pub fn create_interface(client: &std::sync::Arc) -> crate::core::error::Result<()>{ let node = crate::nodes::Node::from_id(client,INTERFACE_NODE_ID,false); node.add_aspect(Interface); node.add_to_scenegraph()?; @@ -403,7 +403,7 @@ fn generate_member(aspect_id: u64, member: &Member) -> TokenStream { (Side::Client, MemberType::Signal) => { quote! { #[doc = #description] - pub fn #name(#argument_decls) -> color_eyre::eyre::Result<()> { + pub fn #name(#argument_decls) -> crate::core::error::Result<()> { let serialized = stardust_xr::schemas::flex::serialize((#argument_uses))?; _node.send_remote_signal(#aspect_id, #opcode, serialized) } @@ -412,7 +412,7 @@ fn generate_member(aspect_id: u64, member: &Member) -> TokenStream { (Side::Client, MemberType::Method) => { quote! { #[doc = #description] - pub async fn #name(#argument_decls) -> color_eyre::eyre::Result<(#return_type, Vec)> { + pub async fn #name(#argument_decls) -> crate::core::error::Result<(#return_type, Vec)> { _node.execute_remote_method_typed(#aspect_id, #opcode, &(#argument_uses), vec![]).await } } @@ -420,13 +420,13 @@ fn generate_member(aspect_id: u64, member: &Member) -> TokenStream { (Side::Server, MemberType::Signal) => { quote! { #[doc = #description] - fn #name(#argument_decls) -> color_eyre::eyre::Result<()>; + fn #name(#argument_decls) -> crate::core::error::Result<()>; } } (Side::Server, MemberType::Method) => { quote! { #[doc = #description] - fn #name(#argument_decls) -> impl std::future::Future> + Send + Sync + 'static; + fn #name(#argument_decls) -> impl std::future::Future> + Send + Sync + 'static; } } } @@ -475,7 +475,7 @@ fn generate_run_member(aspect_name: &Ident, _type: MemberType, member: &Member) #opcode => (move || { #deserialize ::#member_name_ident(_node, _calling_client.clone(), #argument_uses) - })().map_err(|e: color_eyre::Report| stardust_xr::scenegraph::ScenegraphError::MemberError { error: e.to_string() }), + })().map_err(|e: crate::core::error::ServerError| stardust_xr::scenegraph::ScenegraphError::MemberError { error: e.to_string() }), }, MemberType::Method => quote! { #opcode => _method_response.wrap_async(async move { @@ -516,18 +516,18 @@ fn generate_argument_deserialize( } if optional { let mapping = generate_argument_deserialize("o", argument_type, false); - return quote!(#name.map(|o| Ok::<_, color_eyre::eyre::Report>(#mapping)).transpose()?); + return quote!(#name.map(|o| Ok::<_, crate::core::error::ServerError>(#mapping)).transpose()?); } match argument_type { ArgumentType::Color => quote!(color::rgba_linear!(#name[0], #name[1], #name[2], #name[3])), ArgumentType::Vec(v) => { let mapping = generate_argument_deserialize("a", v, false); - quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::>>()?) + quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::>>()?) } ArgumentType::Map(v) => { let mapping = generate_argument_deserialize("a", v, false); - quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::>>()?) + quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::>>()?) } _ => quote!(#name), } @@ -549,11 +549,11 @@ fn generate_argument_serialize( ArgumentType::Color => quote!([#name.c.r, #name.c.g, #name.c.b, #name.a]), ArgumentType::Vec(v) => { let mapping = generate_argument_serialize("a", v, false); - quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::>>()?) + quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::>>()?) } ArgumentType::Map(v) => { let mapping = generate_argument_serialize("a", v, false); - quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::>>()?) + quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::>>()?) } _ => quote!(#name), } diff --git a/src/core/error.rs b/src/core/error.rs new file mode 100644 index 0000000..6dbe502 --- /dev/null +++ b/src/core/error.rs @@ -0,0 +1,75 @@ +use std::any::TypeId; + +use color_eyre::eyre::Report; +use stardust_xr::{ + messenger::MessengerError, + schemas::flex::{ + flexbuffers::{DeserializationError, ReaderError}, + FlexSerializeError, + }, +}; +use stereokit_rust::StereoKitError; +use thiserror::Error; + +pub type Result = std::result::Result; + +#[derive(Error, Debug)] +pub enum ServerError { + #[error("Internal: Unable to get client")] + NoClient, + #[error("Messenger does not exist for this node")] + NoMessenger, + #[error("Messenger error: {0}")] + MessengerError(#[from] MessengerError), + #[error("Remote method error: {0}")] + RemoteMethodError(String), + #[error("Serialization error: {0}")] + SerializationError(#[from] FlexSerializeError), + #[error("Deserialization error: {0}")] + 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}")] + Report(#[from] Report), +} + +#[macro_export] +macro_rules! bail { + ($msg:literal $(,)?) => { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($msg))); + }; + ($err:expr $(,)?) => { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($err))); + }; + ($fmt:expr, $($arg:tt)*) => { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*))); + }; +} + +#[macro_export] +macro_rules! ensure { + ($cond:expr $(,)?) => { + if !$cond { + $crate::ensure!($cond, concat!("Condition failed: `", stringify!($cond), "`")) + } + }; + ($cond:expr, $msg:literal $(,)?) => { + if !$cond { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($msg))); + } + }; + ($cond:expr, $err:expr $(,)?) => { + if !$cond { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($err))); + } + }; + ($cond:expr, $fmt:expr, $($arg:tt)*) => { + if !$cond { + return Err($crate::core::error::ServerError::from(color_eyre::eyre::eyre!($fmt, $($arg)*))); + } + }; +} diff --git a/src/core/mod.rs b/src/core/mod.rs index d2acc81..594fe29 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -2,6 +2,7 @@ pub mod client; pub mod client_state; pub mod delta; pub mod destroy_queue; +pub mod error; pub mod registry; pub mod resource; pub mod scenegraph; diff --git a/src/core/scenegraph.rs b/src/core/scenegraph.rs index 5956639..745b3c3 100644 --- a/src/core/scenegraph.rs +++ b/src/core/scenegraph.rs @@ -1,7 +1,7 @@ +use crate::core::error::Result; use crate::nodes::alias::get_original; use crate::nodes::Node; use crate::{core::client::Client, nodes::Message}; -use color_eyre::eyre::Result; use once_cell::sync::OnceCell; use parking_lot::Mutex; use rustc_hash::FxHashMap; @@ -59,20 +59,20 @@ impl MethodResponseSender { // ) { // let _ = self.0.send(map_method_return(result)); // } - pub fn wrap_sync color_eyre::eyre::Result>(self, f: F) { + pub fn wrap_sync crate::core::error::Result>(self, f: F) { self.send(f().map_err(|e| ScenegraphError::MemberError { error: e.to_string(), })) } pub fn wrap_async( self, - f: impl Future)>> + Send + 'static, + f: impl Future)>> + Send + 'static, ) { tokio::task::spawn(async move { self.0.send(map_method_return(f.await)) }); } } fn map_method_return( - result: color_eyre::eyre::Result<(T, Vec)>, + result: Result<(T, Vec)>, ) -> Result<(Vec, Vec), ScenegraphError> { let (value, fds) = result.map_err(|e| ScenegraphError::MemberError { error: e.to_string(), diff --git a/src/nodes/alias.rs b/src/nodes/alias.rs index 5375749..6cb1036 100644 --- a/src/nodes/alias.rs +++ b/src/nodes/alias.rs @@ -1,6 +1,5 @@ use super::{Aspect, AspectIdentifier, Node}; -use crate::core::{client::Client, registry::Registry}; -use color_eyre::eyre::Result; +use crate::core::{client::Client, error::Result, registry::Registry}; use std::{ ops::Add, sync::{Arc, Weak}, diff --git a/src/nodes/audio.rs b/src/nodes/audio.rs index 928b295..0faf870 100644 --- a/src/nodes/audio.rs +++ b/src/nodes/audio.rs @@ -1,10 +1,11 @@ use super::{Aspect, AspectIdentifier, Node}; use crate::core::client::Client; use crate::core::destroy_queue; +use crate::core::error::Result; use crate::core::registry::Registry; use crate::core::resource::get_resource_file; use crate::nodes::spatial::{Spatial, Transform, SPATIAL_ASPECT_ALIAS_INFO}; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::eyre; use glam::{vec3, Vec4Swizzles}; use once_cell::sync::OnceCell; use parking_lot::Mutex; diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index 7ecf767..7f372b7 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -1,9 +1,8 @@ use super::{Line, LinesAspect}; use crate::{ - core::{client::Client, registry::Registry}, + core::{client::Client, error::Result, registry::Registry}, nodes::{spatial::Spatial, Node}, }; -use color_eyre::eyre::Result; use glam::Vec3; use parking_lot::Mutex; use prisma::Lerp; diff --git a/src/nodes/drawable/mod.rs b/src/nodes/drawable/mod.rs index 00b73a1..3c2ba5c 100644 --- a/src/nodes/drawable/mod.rs +++ b/src/nodes/drawable/mod.rs @@ -10,9 +10,9 @@ use super::{ spatial::{Spatial, Transform}, Aspect, AspectIdentifier, Node, }; -use crate::core::{client::Client, resource::get_resource_file}; +use crate::core::{client::Client, error::Result, resource::get_resource_file}; use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO; -use color_eyre::eyre::{self, Result}; +use color_eyre::eyre::eyre; use model::ModelPart; use parking_lot::Mutex; use stardust_xr::values::ResourceID; @@ -70,7 +70,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::eyre!("Could not find resource"))?; + .ok_or(eyre!("Could not find resource"))?; QUEUED_SKYTEX.lock().replace(resource_path); Ok(()) } @@ -81,7 +81,7 @@ impl InterfaceAspect for Interface { light: ResourceID, ) -> Result<()> { let resource_path = get_resource_file(&light, &calling_client, &[OsStr::new("hdr")]) - .ok_or(eyre::eyre!("Could not find resource"))?; + .ok_or(eyre!("Could not find resource"))?; QUEUED_SKYLIGHT.lock().replace(resource_path); Ok(()) } diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index a47a237..3e98179 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -1,11 +1,13 @@ use super::{MaterialParameter, ModelAspect, ModelPartAspect, MODEL_PART_ASPECT_ALIAS_INFO}; +use crate::bail; use crate::core::client::Client; +use crate::core::error::Result; 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 color_eyre::eyre::{bail, eyre, Result}; +use color_eyre::eyre::eyre; use glam::{Mat4, Vec2, Vec3}; use once_cell::sync::{Lazy, OnceCell}; use parking_lot::Mutex; @@ -363,12 +365,12 @@ impl ModelAspect for Model { calling_client: Arc, id: u64, part_path: String, - ) -> color_eyre::eyre::Result<()> { + ) -> Result<()> { let model = node.get_aspect::()?; let parts = model.parts.lock(); let Some(part) = parts.iter().find(|p| p.path == part_path) else { let paths = parts.iter().map(|p| &p.path).collect::>(); - bail!("Couldn't find model part at path {part_path}, all available paths: {paths:?}",) + bail!("Couldn't find model part at path {part_path}, all available paths: {paths:?}",); }; Alias::create_with_id( &part.space.node().unwrap(), diff --git a/src/nodes/drawable/text.rs b/src/nodes/drawable/text.rs index 7f5c744..ed1ac3c 100644 --- a/src/nodes/drawable/text.rs +++ b/src/nodes/drawable/text.rs @@ -1,8 +1,11 @@ use crate::{ - core::{client::Client, destroy_queue, registry::Registry, resource::get_resource_file}, + core::{ + client::Client, destroy_queue, error::Result, registry::Registry, + resource::get_resource_file, + }, nodes::{spatial::Spatial, Node}, }; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::eyre; use glam::{vec3, Mat4, Vec2}; use once_cell::sync::OnceCell; use parking_lot::Mutex; @@ -59,16 +62,14 @@ impl Text { } fn draw(&self, token: &MainThreadToken) { - let style = - self.style - .get_or_try_init(|| -> Result { - let font = self - .font_path - .as_deref() - .and_then(|path| Font::from_file(path).ok()) - .unwrap_or_default(); - Ok(SkTextStyle::from_font(font, 1.0, Color32::WHITE)) - }); + let style = self.style.get_or_try_init(|| -> Result { + let font = self + .font_path + .as_deref() + .and_then(|path| Font::from_file(path).ok()) + .unwrap_or_default(); + Ok(SkTextStyle::from_font(font, 1.0, Color32::WHITE)) + }); if let Ok(style) = style { let text = self.text.lock(); diff --git a/src/nodes/fields.rs b/src/nodes/fields.rs index 1f595b7..32552fc 100644 --- a/src/nodes/fields.rs +++ b/src/nodes/fields.rs @@ -5,10 +5,11 @@ use super::spatial::{ }; use super::{Aspect, AspectIdentifier, Node}; use crate::core::client::Client; +use crate::core::error::Result; use crate::nodes::spatial::Transform; use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO; use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO; -use color_eyre::eyre::{OptionExt, Result}; +use color_eyre::eyre::OptionExt; use glam::{vec2, vec3, vec3a, Vec3, Vec3A, Vec3Swizzles}; use once_cell::sync::Lazy; use parking_lot::Mutex; @@ -261,7 +262,7 @@ impl InterfaceAspect for Interface { calling_client: Arc, uid: u64, ) -> Result> { - EXPORTED_FIELDS + Ok(EXPORTED_FIELDS .lock() .get(&uid) .map(|s| { @@ -273,7 +274,7 @@ impl InterfaceAspect for Interface { ) .unwrap() }) - .ok_or_eyre("Couldn't find spatial with that ID") + .ok_or_eyre("Couldn't find spatial with that ID")?) } fn create_field( diff --git a/src/nodes/input/method.rs b/src/nodes/input/method.rs index 392bb66..fa0d48e 100644 --- a/src/nodes/input/method.rs +++ b/src/nodes/input/method.rs @@ -4,7 +4,7 @@ use super::{ INPUT_METHOD_REGISTRY, }; use crate::{ - core::{client::Client, registry::Registry}, + core::{client::Client, error::Result, registry::Registry}, nodes::{ alias::{Alias, AliasList}, fields::{Field, FIELD_ALIAS_INFO}, @@ -12,7 +12,6 @@ use crate::{ Node, }, }; -use color_eyre::eyre::Result; use parking_lot::Mutex; use stardust_xr::values::Datamap; use std::sync::{Arc, Weak}; diff --git a/src/nodes/input/mod.rs b/src/nodes/input/mod.rs index 86e80cb..3d01c17 100644 --- a/src/nodes/input/mod.rs +++ b/src/nodes/input/mod.rs @@ -13,11 +13,11 @@ use super::fields::Field; use super::spatial::Spatial; use super::Aspect; use super::AspectIdentifier; +use crate::core::error::Result; use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO; use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO; use crate::{core::client::Client, nodes::Node}; use crate::{core::registry::Registry, nodes::spatial::Transform}; -use color_eyre::eyre::Result; use stardust_xr::values::Datamap; use std::sync::Arc; diff --git a/src/nodes/items/camera.rs b/src/nodes/items/camera.rs index b54ecc6..b72615f 100644 --- a/src/nodes/items/camera.rs +++ b/src/nodes/items/camera.rs @@ -1,4 +1,6 @@ use super::{create_item_acceptor_flex, register_item_ui_flex, Item, ItemType}; +use crate::bail; +use crate::core::error::Result; use crate::nodes::items::ITEM_ACCEPTOR_ASPECT_ALIAS_INFO; use crate::nodes::items::ITEM_ASPECT_ALIAS_INFO; use crate::nodes::Aspect; @@ -15,7 +17,6 @@ use crate::{ Message, Node, }, }; -use color_eyre::eyre::{bail, eyre, Result}; use glam::Mat4; use lazy_static::lazy_static; use mint::{ColumnMatrix4, Vector2}; @@ -99,7 +100,7 @@ impl CameraItem { response.wrap_sync(move || { let ItemType::Camera(_camera) = &node.get_aspect::().unwrap().specialization else { - return Err(eyre!("Wrong item type?")); + bail!("Wrong item type?"); }; Ok(serialize(())?.into()) }); @@ -111,7 +112,7 @@ impl CameraItem { message: Message, ) -> Result<()> { let ItemType::Camera(camera) = &node.get_aspect::().unwrap().specialization else { - bail!("Wrong item type?") + bail!("Wrong item type?"); }; let model_part_node = calling_client.get_node("Model part", deserialize(&message.data).unwrap())?; diff --git a/src/nodes/items/mod.rs b/src/nodes/items/mod.rs index 6b0535a..5844082 100644 --- a/src/nodes/items/mod.rs +++ b/src/nodes/items/mod.rs @@ -8,11 +8,12 @@ use super::fields::{Field, FIELD_ALIAS_INFO}; use super::spatial::Spatial; use super::{Alias, Aspect, AspectIdentifier, Node}; use crate::core::client::Client; +use crate::core::error::Result; use crate::core::registry::Registry; +use crate::ensure; use crate::nodes::alias::AliasInfo; use crate::nodes::spatial::Transform; use crate::nodes::spatial::SPATIAL_ASPECT_ALIAS_INFO; -use color_eyre::eyre::{ensure, Result}; use parking_lot::Mutex; use std::hash::Hash; use std::sync::{Arc, Weak}; diff --git a/src/nodes/items/panel.rs b/src/nodes/items/panel.rs index 28ce336..a3cb813 100644 --- a/src/nodes/items/panel.rs +++ b/src/nodes/items/panel.rs @@ -1,5 +1,7 @@ use super::camera::CameraItemAcceptor; use super::{create_item_acceptor_flex, register_item_ui_flex}; +use crate::bail; +use crate::core::error::Result; use crate::nodes::items::ITEM_ACCEPTOR_ASPECT_ALIAS_INFO; use crate::nodes::items::ITEM_ASPECT_ALIAS_INFO; use crate::nodes::{Aspect, AspectIdentifier}; @@ -15,7 +17,6 @@ use crate::{ Node, }, }; -use color_eyre::eyre::{bail, Result}; use glam::Mat4; use lazy_static::lazy_static; use mint::Vector2; @@ -518,7 +519,7 @@ impl InterfaceAspect for Interface { ) -> Result { let keymaps = KEYMAPS.lock(); let Some(keymap) = keymaps.get(KeyData::from_ffi(keymap_id).into()) else { - bail!("Could not find keymap. Try registering it") + bail!("Could not find keymap. Try registering it"); }; Ok(keymap.clone()) diff --git a/src/nodes/mod.rs b/src/nodes/mod.rs index 991effe..ef3289d 100644 --- a/src/nodes/mod.rs +++ b/src/nodes/mod.rs @@ -9,9 +9,9 @@ pub mod spatial; use self::alias::Alias; use crate::core::client::Client; +use crate::core::error::{Result, ServerError}; use crate::core::registry::Registry; use crate::core::scenegraph::MethodResponseSender; -use color_eyre::eyre::{eyre, Result}; use parking_lot::Mutex; use portable_atomic::{AtomicBool, Ordering}; use rustc_hash::FxHashMap; @@ -20,7 +20,7 @@ use spatial::Spatial; use stardust_xr::messenger::MessageSenderHandle; use stardust_xr::scenegraph::ScenegraphError; use stardust_xr::schemas::flex::{deserialize, serialize}; -use std::any::Any; +use std::any::{Any, TypeId}; use std::fmt::Debug; use std::os::fd::OwnedFd; use std::sync::{Arc, Weak}; @@ -112,14 +112,14 @@ impl Node { pub fn add_to_scenegraph(self) -> Result> { Ok(self .get_client() - .ok_or_else(|| eyre!("Internal: Unable to get client"))? + .ok_or(ServerError::NoClient)? .scenegraph .add_node(self)) } pub fn add_to_scenegraph_owned(self) -> Result { Ok(OwnedNode( self.get_client() - .ok_or_else(|| eyre!("Internal: Unable to get client"))? + .ok_or(ServerError::NoClient)? .scenegraph .add_node(self), )) @@ -274,13 +274,13 @@ impl Node { let message_sender_handle = self .message_sender_handle .as_ref() - .ok_or(eyre!("Messenger does not exist for this node"))?; + .ok_or(ServerError::NoMessenger)?; let serialized = serialize(input)?; let result = message_sender_handle .method(self.id, aspect_id, method, &serialized, fds)? .await - .map_err(|e| eyre!(e))?; + .map_err(ServerError::RemoteMethodError)?; let (message, fds) = result.into_components(); let deserialized: D = deserialize(&message)?; @@ -341,7 +341,7 @@ impl Aspects { .cloned() .map(|a| a.as_any()) .and_then(|a| Arc::downcast(a).ok()) - .ok_or(eyre!("Couldn't get aspect")) + .ok_or(ServerError::NoAspect(TypeId::of::())) } } impl Drop for Aspects { diff --git a/src/nodes/root.rs b/src/nodes/root.rs index 8151114..0f9417b 100644 --- a/src/nodes/root.rs +++ b/src/nodes/root.rs @@ -1,11 +1,12 @@ use super::spatial::Spatial; use super::{Aspect, AspectIdentifier, Node}; +use crate::bail; use crate::core::client::Client; use crate::core::client_state::ClientStateParsed; +use crate::core::error::Result; use crate::core::registry::Registry; use crate::nodes::spatial::SPATIAL_REF_ASPECT_ALIAS_INFO; use crate::session::connection_env; -use color_eyre::eyre::{bail, Result}; use glam::Mat4; use std::path::PathBuf; use std::sync::Arc; @@ -98,7 +99,7 @@ impl RootAspect for Root { } #[doc = "Cleanly disconnect from the server"] - fn disconnect(_node: Arc, calling_client: Arc) -> color_eyre::eyre::Result<()> { + fn disconnect(_node: Arc, calling_client: Arc) -> Result<()> { calling_client.disconnect(Ok(())); Ok(()) } diff --git a/src/nodes/spatial/mod.rs b/src/nodes/spatial/mod.rs index b50dac7..cba7b0b 100644 --- a/src/nodes/spatial/mod.rs +++ b/src/nodes/spatial/mod.rs @@ -4,10 +4,12 @@ use self::zone::Zone; use super::alias::Alias; use super::fields::{Field, FieldTrait}; use super::{Aspect, AspectIdentifier}; +use crate::bail; use crate::core::client::Client; +use crate::core::error::Result; use crate::core::registry::Registry; use crate::nodes::{Node, OWNED_ASPECT_ALIAS_INFO}; -use color_eyre::eyre::{eyre, OptionExt, Result}; +use color_eyre::eyre::OptionExt; use glam::{vec3a, Mat4, Quat, Vec3}; use mint::Vector3; use once_cell::sync::OnceCell; @@ -208,7 +210,7 @@ impl Spatial { .map(|parent| self.is_ancestor_of((*parent).clone())) .unwrap_or(false); if is_ancestor { - return Err(eyre!("Setting spatial parent would cause a loop")); + bail!("Setting spatial parent would cause a loop"); } self.set_parent(parent); @@ -223,7 +225,7 @@ impl Spatial { .map(|parent| self.is_ancestor_of((*parent).clone())) .unwrap_or(false); if is_ancestor { - return Err(eyre!("Setting spatial parent would cause a loop")); + bail!("Setting spatial parent would cause a loop"); } self.set_local_transform(Spatial::space_to_space_matrix( @@ -458,7 +460,7 @@ impl InterfaceAspect for Interface { calling_client: Arc, uid: u64, ) -> Result> { - EXPORTED_SPATIALS + Ok(EXPORTED_SPATIALS .lock() .get(&uid) .map(|s| { @@ -470,6 +472,6 @@ impl InterfaceAspect for Interface { ) .unwrap() }) - .ok_or_eyre("Couldn't find spatial with that ID") + .ok_or_eyre("Couldn't find spatial with that ID")?) } } diff --git a/src/nodes/spatial/zone.rs b/src/nodes/spatial/zone.rs index 420f33c..2779ded 100644 --- a/src/nodes/spatial/zone.rs +++ b/src/nodes/spatial/zone.rs @@ -3,14 +3,13 @@ use super::{ ZONEABLE_REGISTRY, }; use crate::{ - core::{client::Client, registry::Registry}, + core::{client::Client, error::Result, registry::Registry}, nodes::{ alias::{get_original, Alias, AliasList}, fields::{Field, FieldTrait}, Node, }, }; -use color_eyre::eyre::Result; use glam::vec3a; use std::sync::{Arc, Weak}; diff --git a/src/wayland/xdg_shell.rs b/src/wayland/xdg_shell.rs index e5d8e57..3500585 100644 --- a/src/wayland/xdg_shell.rs +++ b/src/wayland/xdg_shell.rs @@ -4,13 +4,16 @@ use super::{ surface::CoreSurface, utils::*, }; -use crate::nodes::{ - drawable::model::ModelPart, - items::panel::{ - Backend, ChildInfo, Geometry, PanelItem, PanelItemInitData, SurfaceId, ToplevelInfo, +use crate::{ + core::error::Result, + nodes::{ + drawable::model::ModelPart, + items::panel::{ + Backend, ChildInfo, Geometry, PanelItem, PanelItemInitData, SurfaceId, ToplevelInfo, + }, }, }; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::eyre; use mint::Vector2; use parking_lot::Mutex; use rand::Rng; -- 2.49.1