switch to color_eyre instead of anyhow

This commit is contained in:
Nova
2022-12-02 13:58:54 -05:00
parent 03ccf9127d
commit d7a607a663
29 changed files with 114 additions and 118 deletions

View File

@@ -7,7 +7,7 @@ use crate::core::node_collections::LifeLinkedNodeMap;
use crate::core::registry::Registry;
use crate::nodes::fields::find_field;
use crate::nodes::spatial::find_spatial_parent;
use anyhow::{anyhow, ensure, Result};
use color_eyre::eyre::{ensure, eyre, Result};
use glam::vec3a;
use mint::{Quaternion, Vector3};
use nanoid::nanoid;
@@ -37,9 +37,9 @@ pub struct Mask(pub Vec<u8>);
impl Mask {
pub fn get_mask(&self) -> Result<flexbuffers::MapReader<&[u8]>> {
flexbuffers::Reader::get_root(self.0.as_slice())
.map_err(|_| anyhow!("Mask is not a valid flexbuffer"))?
.map_err(|_| eyre!("Mask is not a valid flexbuffer"))?
.get_map()
.map_err(|_| anyhow!("Mask is not a valid map"))
.map_err(|_| eyre!("Mask is not a valid map"))
}
}

View File

@@ -5,7 +5,7 @@ use crate::{
Node,
},
};
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::Vec3A;
use mint::Vector3;
use parking_lot::Mutex;

View File

@@ -4,7 +4,7 @@ pub mod text;
use super::Node;
use crate::core::client::Client;
use anyhow::Result;
use color_eyre::eyre::Result;
use parking_lot::Mutex;
use serde::Deserialize;
use stardust_xr::schemas::flex::deserialize;

View File

@@ -4,7 +4,7 @@ use crate::core::destroy_queue;
use crate::core::registry::Registry;
use crate::core::resource::ResourceID;
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use anyhow::{anyhow, ensure, Result};
use color_eyre::eyre::{ensure, eyre, Result};
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use prisma::{Rgb, Rgba};
@@ -66,12 +66,12 @@ impl Model {
.get_file(
&node
.get_client()
.ok_or_else(|| anyhow!("Client not found"))?
.ok_or_else(|| eyre!("Client not found"))?
.base_resource_prefixes
.lock()
.clone(),
)
.ok_or_else(|| anyhow!("Resource not found"))?,
.ok_or_else(|| eyre!("Resource not found"))?,
);
let _ = node.model.set(model_arc.clone());
Ok(model_arc)

View File

@@ -5,7 +5,7 @@ use crate::{
Node,
},
};
use anyhow::{anyhow, ensure, Result};
use color_eyre::eyre::{ensure, eyre, Result};
use glam::{vec3, Mat4, Vec2};
use mint::Vector2;
use once_cell::sync::OnceCell;
@@ -63,9 +63,7 @@ impl Text {
"Internal: Node already has text attached!"
);
let client = node
.get_client()
.ok_or_else(|| anyhow!("Client not found"))?;
let client = node.get_client().ok_or_else(|| eyre!("Client not found"))?;
let text = TEXT_REGISTRY.add(Text {
space: node.spatial.get().unwrap().clone(),
font_path: font_resource_id
@@ -90,21 +88,21 @@ impl Text {
}
fn draw(&self, sk: &StereoKit, draw_ctx: &DrawContext) {
let style =
self.style
.get_or_try_init(|| -> Result<SendWrapper<TextStyle>, anyhow::Error> {
let font = self
.font_path
.as_deref()
.and_then(|path| Font::from_file(sk, path))
.unwrap_or(Font::default(sk));
Ok(SendWrapper::new(TextStyle::new(
sk,
font,
1.0,
Rgba::new(Rgb::new(1.0, 1.0, 1.0), 1.0),
)))
});
let style = self.style.get_or_try_init(
|| -> Result<SendWrapper<TextStyle>, color_eyre::eyre::Error> {
let font = self
.font_path
.as_deref()
.and_then(|path| Font::from_file(sk, path))
.unwrap_or(Font::default(sk));
Ok(SendWrapper::new(TextStyle::new(
sk,
font,
1.0,
Rgba::new(Rgb::new(1.0, 1.0, 1.0), 1.0),
)))
},
);
if let Ok(style) = style {
let data = self.data.lock();

View File

@@ -1,7 +1,7 @@
use super::{Field, FieldTrait, Node};
use crate::core::client::Client;
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::{vec3, vec3a, Vec3, Vec3A};
use mint::Vector3;
use parking_lot::Mutex;

View File

@@ -1,7 +1,7 @@
use super::{Field, FieldTrait, Node};
use crate::core::client::Client;
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::{swizzles::*, vec2, Vec3A};
use portable_atomic::AtomicF32;
use serde::Deserialize;

View File

@@ -12,7 +12,7 @@ use super::spatial::Spatial;
use super::Node;
use crate::core::client::Client;
use crate::nodes::spatial::find_reference_space;
use anyhow::Result;
use color_eyre::eyre::Result;
use glam::{vec2, vec3a, Vec3, Vec3A};
use mint::Vector3;
use serde::{Deserialize, Serialize};

View File

@@ -1,7 +1,7 @@
use super::{Field, FieldTrait, Node};
use crate::core::client::Client;
use crate::nodes::spatial::{find_spatial_parent, Spatial};
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::{Mat4, Vec3A};
use mint::Vector3;
use portable_atomic::AtomicF32;

View File

@@ -1,7 +1,7 @@
use super::{Field, FieldTrait, Node};
use crate::core::client::Client;
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::{swizzles::*, vec2, Vec3A};
use portable_atomic::AtomicF32;
use serde::Deserialize;

View File

@@ -13,7 +13,7 @@ use crate::core::client::Client;
use crate::core::eventloop::FRAME;
use crate::core::registry::Registry;
use crate::nodes::fields::find_field;
use anyhow::{ensure, Result};
use color_eyre::eyre::{ensure, Result};
use glam::Mat4;
use nanoid::nanoid;
use parking_lot::Mutex;

View File

@@ -4,7 +4,7 @@ use crate::nodes::fields::Field;
use crate::nodes::input::{InputMethod, InputType};
use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
use crate::nodes::Node;
use anyhow::Result;
use color_eyre::eyre::Result;
use glam::{vec3a, Mat4};
use serde::Deserialize;
use stardust_xr::schemas::flat::{Datamap, InputDataType, Tip as FlatTip};

View File

@@ -10,7 +10,7 @@ use crate::{
Node,
},
};
use anyhow::{anyhow, Result};
use color_eyre::eyre::{eyre, Result};
use lazy_static::lazy_static;
use serde::Deserialize;
use stardust_xr::{
@@ -46,7 +46,7 @@ impl EnvironmentItem {
fn get_path_flex(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<Vec<u8>> {
let ItemType::Environment(environment_item) = &node.item.get().unwrap().specialization else {
return Err(anyhow!("Wrong item type?"))
return Err(eyre!("Wrong item type?"))
};
Ok(flexbuffers::singleton(environment_item.path.as_str()))
}

View File

@@ -11,7 +11,7 @@ use crate::nodes::alias::AliasInfo;
use crate::nodes::fields::find_field;
#[cfg(feature = "wayland")]
use crate::wayland::panel_item::{PanelItem, ITEM_TYPE_INFO_PANEL};
use anyhow::{anyhow, ensure, Result};
use color_eyre::eyre::{ensure, eyre, Result};
use lazy_static::lazy_static;
use nanoid::nanoid;
use parking_lot::Mutex;
@@ -372,7 +372,7 @@ fn type_info(name: &str) -> Result<&'static TypeInfo> {
"environment" => Ok(&ITEM_TYPE_INFO_ENVIRONMENT),
#[cfg(feature = "wayland")]
"panel" => Ok(&ITEM_TYPE_INFO_PANEL),
_ => Err(anyhow!("Invalid item type")),
_ => Err(eyre!("Invalid item type")),
}
}

View File

@@ -9,7 +9,7 @@ pub mod root;
pub mod spatial;
pub mod startup;
use anyhow::{anyhow, Result};
use color_eyre::eyre::{bail, eyre, Result};
use nanoid::nanoid;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
@@ -162,7 +162,7 @@ impl Node {
{
aspect_fn(self)
.get()
.ok_or_else(|| anyhow!("{} is not a {} node", node_name, aspect_type))
.ok_or_else(|| eyre!("{} is not a {} node", node_name, aspect_type))
}
pub fn send_local_signal(
@@ -185,8 +185,9 @@ impl Node {
.local_signals
.get(method)
.ok_or(ScenegraphError::SignalNotFound)?;
signal(self, calling_client, data)
.map_err(|error| ScenegraphError::SignalError { error })
signal(self, calling_client, data).map_err(|error| ScenegraphError::SignalError {
error: error.to_string(),
})
}
}
pub fn execute_local_method(
@@ -209,8 +210,9 @@ impl Node {
.local_methods
.get(method)
.ok_or(ScenegraphError::MethodNotFound)?;
method(self, calling_client, data)
.map_err(|error| ScenegraphError::MethodError { error })
method(self, calling_client, data).map_err(|error| ScenegraphError::MethodError {
error: error.to_string(),
})
}
}
pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
@@ -236,17 +238,15 @@ impl Node {
Ok(())
}
pub async fn execute_remote_method(&self, method: &str, data: Vec<u8>) -> Result<Vec<u8>> {
if let Some(client) = self.get_client() {
match client.message_sender_handle.as_ref() {
None => Err(anyhow!("Messenger does not exist for this node's client")),
Some(message_sender_handle) => {
message_sender_handle
.method(self.path.as_str(), method, &data)?
.await
}
}
} else {
Err(anyhow!("Client does not exist somehow?"))
}
let Some(client) = self.get_client() else {bail!("Client does not exist somehow?")};
let message_sender_handle = client
.message_sender_handle
.as_ref()
.ok_or(eyre!("Messenger does not exist for this node's client"))?;
message_sender_handle
.method(self.path.as_str(), method, &data)?
.await
.map_err(|e| eyre!(e))
}
}

View File

@@ -3,7 +3,7 @@ use super::startup::DESKTOP_STARTUP_IDS;
use super::Node;
use crate::core::client::Client;
use crate::core::registry::Registry;
use anyhow::{anyhow, Result};
use color_eyre::eyre::{eyre, Result};
use glam::Mat4;
use stardust_xr::schemas::flex::{deserialize, serialize};
@@ -39,7 +39,7 @@ impl Root {
let startup_settings = DESKTOP_STARTUP_IDS
.lock()
.remove(flexbuffers::Reader::get_root(data)?.get_str()?)
.ok_or_else(|| anyhow!("Desktop startup ID not found in the list!"))?;
.ok_or_else(|| eyre!("Desktop startup ID not found in the list!"))?;
node.spatial
.get()
.unwrap()

View File

@@ -4,7 +4,7 @@ use self::zone::{create_zone_flex, Zone};
use super::Node;
use crate::core::client::Client;
use crate::core::registry::Registry;
use anyhow::{anyhow, ensure, Result};
use color_eyre::eyre::{ensure, eyre, Result};
use glam::{vec3a, Mat4, Quat};
use mint::Vector3;
use nanoid::nanoid;
@@ -147,7 +147,7 @@ impl Spatial {
.map(|parent| self.is_ancestor_of(parent.clone()))
.unwrap_or(false);
if is_ancestor {
return Err(anyhow!("Setting spatial parent would cause a loop"));
return Err(eyre!("Setting spatial parent would cause a loop"));
}
*self.parent.lock() = parent.cloned();
@@ -160,7 +160,7 @@ impl Spatial {
.map(|parent| self.is_ancestor_of(parent.clone()))
.unwrap_or(false);
if is_ancestor {
return Err(anyhow!("Setting spatial parent would cause a loop"));
return Err(eyre!("Setting spatial parent would cause a loop"));
}
self.set_local_transform(Spatial::space_to_space_matrix(
@@ -180,7 +180,7 @@ impl Spatial {
let this_spatial = node
.spatial
.get()
.ok_or_else(|| anyhow!("Node doesn't have a spatial?"))?;
.ok_or_else(|| eyre!("Node doesn't have a spatial?"))?;
let relative_spatial = find_reference_space(&calling_client, deserialize(data)?)?;
let (scale, rotation, position) = Spatial::space_to_space_matrix(
@@ -295,7 +295,7 @@ pub fn find_spatial(
calling_client: &Arc<Client>,
node_name: &'static str,
node_path: &str,
) -> anyhow::Result<Arc<Spatial>> {
) -> color_eyre::eyre::Result<Arc<Spatial>> {
calling_client
.get_node(node_name, node_path)?
.get_aspect(node_name, "spatial", |n| &n.spatial)
@@ -304,13 +304,13 @@ pub fn find_spatial(
pub fn find_spatial_parent(
calling_client: &Arc<Client>,
node_path: &str,
) -> anyhow::Result<Arc<Spatial>> {
) -> color_eyre::eyre::Result<Arc<Spatial>> {
find_spatial(calling_client, "Spatial parent", node_path)
}
pub fn find_reference_space(
calling_client: &Arc<Client>,
node_path: &str,
) -> anyhow::Result<Arc<Spatial>> {
) -> color_eyre::eyre::Result<Arc<Spatial>> {
find_spatial(calling_client, "Reference space", node_path)
}

View File

@@ -8,7 +8,7 @@ use crate::{
Node,
},
};
use anyhow::Result;
use color_eyre::eyre::Result;
use glam::vec3a;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
@@ -81,12 +81,12 @@ impl Zone {
}
fn update(node: &Node, _calling_client: Arc<Client>, _data: &[u8]) -> Result<()> {
let zone = node.zone.get().unwrap();
let Some(field) = zone.field.upgrade() else { return Err(anyhow::anyhow!("Zone's field has been destroyed")) };
let Some(field) = zone.field.upgrade() else { return Err(color_eyre::eyre::eyre!("Zone's field has been destroyed")) };
let Some((zone_client, zone_node)) = zone
.spatial
.node
.upgrade()
.and_then(|n| n.get_client().zip(Some(n))) else { return Err(anyhow::anyhow!("No client on node?")) };
.and_then(|n| n.get_client().zip(Some(n))) else { return Err(color_eyre::eyre::eyre!("No client on node?")) };
let mut old_zoneables = zone.zoneables.lock();
for (_uid, zoneable) in old_zoneables.iter() {
zoneable.destroy();

View File

@@ -1,7 +1,7 @@
use crate::core::client::Client;
use super::Node;
use anyhow::{anyhow, Result};
use color_eyre::eyre::{eyre, Result};
use glam::Mat4;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
@@ -27,11 +27,11 @@ impl StartupSettings {
let spatial_node = calling_client
.scenegraph
.get_node(startup_id)
.ok_or_else(|| anyhow!("Root spatial node does not exist"))?;
.ok_or_else(|| eyre!("Root spatial node does not exist"))?;
let spatial = spatial_node
.spatial
.get()
.ok_or_else(|| anyhow!("Root spatial node is not a spatial"))?;
.ok_or_else(|| eyre!("Root spatial node is not a spatial"))?;
node.startup_settings.get().unwrap().lock().transform = spatial.global_transform();
Ok(())