feat(scenegraph): use ScenegraphError signal/node errors

This commit is contained in:
Nova
2022-06-12 11:35:52 -04:00
parent 25edd845c1
commit 5db13aa484
2 changed files with 12 additions and 9 deletions

View File

@@ -48,7 +48,6 @@ impl<'a> scenegraph::Scenegraph for Scenegraph<'a> {
.ok_or(ScenegraphError::NodeNotFound)? .ok_or(ScenegraphError::NodeNotFound)?
.borrow() .borrow()
.send_local_signal(self.get_client(), method, data) .send_local_signal(self.get_client(), method, data)
.map_err(|_| ScenegraphError::SignalNotFound)
} }
fn execute_method( fn execute_method(
&self, &self,
@@ -60,6 +59,5 @@ impl<'a> scenegraph::Scenegraph for Scenegraph<'a> {
.ok_or(ScenegraphError::NodeNotFound)? .ok_or(ScenegraphError::NodeNotFound)?
.borrow() .borrow()
.execute_local_method(self.get_client(), method, data) .execute_local_method(self.get_client(), method, data)
.map_err(|_| ScenegraphError::MethodNotFound)
} }
} }

View File

@@ -2,7 +2,8 @@ use super::data::PulseSender;
use super::field::Field; use super::field::Field;
use super::spatial::Spatial; use super::spatial::Spatial;
use crate::core::client::Client; use crate::core::client::Client;
use anyhow::{anyhow, Result}; use anyhow::Result;
use libstardustxr::scenegraph::ScenegraphError;
use std::rc::{Rc, Weak}; use std::rc::{Rc, Weak};
use std::sync::Arc; use std::sync::Arc;
use std::{collections::HashMap, vec::Vec}; use std::{collections::HashMap, vec::Vec};
@@ -81,24 +82,28 @@ impl<'a> Node<'a> {
calling_client: Rc<Client>, calling_client: Rc<Client>,
method: &str, method: &str,
data: &[u8], data: &[u8],
) -> Result<()> { ) -> Result<(), ScenegraphError> {
let signal = self let signal = self
.local_signals .local_signals
.get(method) .get(method)
.ok_or_else(|| anyhow!("Signal {} not found", method))?; .ok_or(ScenegraphError::SignalNotFound)?;
signal(self, calling_client, data) signal(self, calling_client, data).map_err(|err| ScenegraphError::SignalError {
error: format!("{}", err),
})
} }
pub fn execute_local_method( pub fn execute_local_method(
&self, &self,
calling_client: Rc<Client>, calling_client: Rc<Client>,
method: &str, method: &str,
data: &[u8], data: &[u8],
) -> Result<Vec<u8>> { ) -> Result<Vec<u8>, ScenegraphError> {
let method = self let method = self
.local_methods .local_methods
.get(method) .get(method)
.ok_or_else(|| anyhow!("Method {} not found", method))?; .ok_or(ScenegraphError::MethodNotFound)?;
method(self, calling_client, data) method(self, calling_client, data).map_err(|err| ScenegraphError::MethodError {
error: format!("{}", err),
})
} }
// pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> { // pub fn send_remote_signal(&self, method: &str, data: &[u8]) -> Result<()> {
// self.get_client() // self.get_client()