start to convert ad-hoc errors to explicit types

This commit is contained in:
ash lea
2024-12-30 15:28:39 -05:00
committed by Nova
parent 3b996c46e2
commit a5f087d29f
23 changed files with 166 additions and 78 deletions

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();