start to convert ad-hoc errors to explicit types #30

Merged
ashkitten merged 1 commits from explicit-error-type into dev 2024-12-30 20:48:15 -05:00
23 changed files with 166 additions and 78 deletions

13
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"

View File

@@ -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<crate::core::client::Client>) -> color_eyre::eyre::Result<()>{
pub fn create_interface(client: &std::sync::Arc<crate::core::client::Client>) -> 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<std::os::fd::OwnedFd>)> {
pub async fn #name(#argument_decls) -> crate::core::error::Result<(#return_type, Vec<std::os::fd::OwnedFd>)> {
_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<Output = color_eyre::eyre::Result<#return_type>> + Send + Sync + 'static;
fn #name(#argument_decls) -> impl std::future::Future<Output = crate::core::error::Result<#return_type>> + Send + Sync + 'static;
}
}
}
@@ -475,7 +475,7 @@ fn generate_run_member(aspect_name: &Ident, _type: MemberType, member: &Member)
#opcode => (move || {
#deserialize
<Self as #aspect_name>::#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::<color_eyre::eyre::Result<Vec<_>>>()?)
quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::<crate::core::error::Result<Vec<_>>>()?)
}
ArgumentType::Map(v) => {
let mapping = generate_argument_deserialize("a", v, false);
quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::<color_eyre::eyre::Result<rustc_hash::FxHashMap<String, _>>>()?)
quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::<crate::core::error::Result<rustc_hash::FxHashMap<String, _>>>()?)
}
_ => 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::<color_eyre::eyre::Result<Vec<_>>>()?)
quote!(#name.into_iter().map(|a| Ok(#mapping)).collect::<crate::core::error::Result<Vec<_>>>()?)
}
ArgumentType::Map(v) => {
let mapping = generate_argument_serialize("a", v, false);
quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::<color_eyre::eyre::Result<rustc_hash::FxHashMap<String, _>>>()?)
quote!(#name.into_iter().map(|(k, a)| Ok((k, #mapping))).collect::<crate::core::error::Result<rustc_hash::FxHashMap<String, _>>>()?)
}
_ => quote!(#name),
}

75
src/core/error.rs Normal file
View File

@@ -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<T, E = ServerError> = std::result::Result<T, E>;
#[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)*)));
}
};
}

View File

@@ -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;

View File

@@ -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<F: FnOnce() -> color_eyre::eyre::Result<Message>>(self, f: F) {
pub fn wrap_sync<F: FnOnce() -> crate::core::error::Result<Message>>(self, f: F) {
self.send(f().map_err(|e| ScenegraphError::MemberError {
error: e.to_string(),
}))
}
pub fn wrap_async<T: Serialize>(
self,
f: impl Future<Output = color_eyre::eyre::Result<(T, Vec<OwnedFd>)>> + Send + 'static,
f: impl Future<Output = Result<(T, Vec<OwnedFd>)>> + Send + 'static,
) {
tokio::task::spawn(async move { self.0.send(map_method_return(f.await)) });
}
}
fn map_method_return<T: Serialize>(
result: color_eyre::eyre::Result<(T, Vec<OwnedFd>)>,
result: Result<(T, Vec<OwnedFd>)>,
) -> Result<(Vec<u8>, Vec<OwnedFd>), ScenegraphError> {
let (value, fds) = result.map_err(|e| ScenegraphError::MemberError {
error: e.to_string(),

View File

@@ -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},

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<Node>, calling_client: Arc<Client>, 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(())
}

View File

@@ -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<Client>,
id: u64,
part_path: String,
) -> color_eyre::eyre::Result<()> {
) -> Result<()> {
let model = node.get_aspect::<Model>()?;
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::<Vec<_>>();
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(),

View File

@@ -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<SkTextStyle, color_eyre::eyre::Error> {
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<SkTextStyle> {
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();

View File

@@ -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<Client>,
uid: u64,
) -> Result<Arc<Node>> {
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(

View File

@@ -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};

View File

@@ -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;

View File

@@ -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::<Item>().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::<Item>().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())?;

View File

@@ -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};

View File

@@ -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<String> {
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())

View File

@@ -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<Arc<Node>> {
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<OwnedNode> {
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::<A>()))
}
}
impl Drop for Aspects {

View File

@@ -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<Node>, calling_client: Arc<Client>) -> color_eyre::eyre::Result<()> {
fn disconnect(_node: Arc<Node>, calling_client: Arc<Client>) -> Result<()> {
calling_client.disconnect(Ok(()));
Ok(())
}

View File

@@ -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<Client>,
uid: u64,
) -> Result<Arc<Node>> {
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")?)
}
}

View File

@@ -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};

View File

@@ -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;