-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start to convert ad-hoc errors to explicit types
- Loading branch information
1 parent
0adde69
commit 8708f24
Showing
23 changed files
with
166 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)*))); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.