-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added WorkspaceError{,Kind} * Added workspace error kind for sandbox * Replaced types errors w/ WorkspaceError * Moved from ErrorKind to thiserror * Added SerializationError type * Added ExecutionError * Added errors to network related items * Added error handling to view * Moved all client anyhow Error to workspace Error * Rearrange Error to be at top level * More serialization error for result.rs * Last bits of result.rs errors * Added sandbox specific error handling * Sandbox patch * Final bit of anyhow::Result removed * Specific RpcError * Cleanup * Added ParseError specific kind * Surface WorkspacError * Small cleanup * Added some docs * Added more docs * Moved errors to error module & added RpcError into client.rs * Changed internal repr of RpcError * Some more cleanup * Cleanup Result path * Fmt * Clippy * Fmt again * Addressed most comments * Fixed Sync/Send | remove AccountError | made ParseError(String) * Fix io error from_file * Moved Error to mostly opaque type * Added downcasting and docs * Added deferred error handling on args_{json, borsh} * Fix test * Export Result to workspaces root * Remove exposed from impls * Addressed comments * Make less redundant usage of deferred error * Added error message w/ timeout env var
- Loading branch information
1 parent
aed7aa5
commit 7de5010
Showing
32 changed files
with
619 additions
and
300 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
use std::borrow::Cow; | ||
use std::fmt; | ||
|
||
use super::{Error, ErrorKind, ErrorRepr, RpcErrorCode, SandboxErrorCode}; | ||
|
||
impl ErrorKind { | ||
pub(crate) fn custom<E>(self, error: E) -> Error | ||
where | ||
E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||
{ | ||
Error::custom(self, error) | ||
} | ||
|
||
pub(crate) fn message<T>(self, msg: T) -> Error | ||
where | ||
T: Into<Cow<'static, str>>, | ||
{ | ||
Error::message(self, msg) | ||
} | ||
} | ||
|
||
impl Error { | ||
pub(crate) fn full<T, E>(kind: ErrorKind, msg: T, error: E) -> Self | ||
where | ||
T: Into<Cow<'static, str>>, | ||
E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||
{ | ||
Self { | ||
repr: ErrorRepr::Full { | ||
kind, | ||
message: msg.into(), | ||
error: error.into(), | ||
}, | ||
} | ||
} | ||
|
||
pub(crate) fn custom<E>(kind: ErrorKind, error: E) -> Self | ||
where | ||
E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||
{ | ||
Self { | ||
repr: ErrorRepr::Custom { | ||
kind, | ||
error: error.into(), | ||
}, | ||
} | ||
} | ||
|
||
pub(crate) fn message<T>(kind: ErrorKind, msg: T) -> Self | ||
where | ||
T: Into<Cow<'static, str>>, | ||
{ | ||
Self { | ||
repr: ErrorRepr::Message { | ||
kind, | ||
message: msg.into(), | ||
}, | ||
} | ||
} | ||
|
||
pub(crate) fn simple(kind: ErrorKind) -> Self { | ||
Self { | ||
repr: ErrorRepr::Simple(kind), | ||
} | ||
} | ||
|
||
/// Returns the corresponding [`ErrorKind`] for this error. | ||
pub fn kind(&self) -> &ErrorKind { | ||
match &self.repr { | ||
ErrorRepr::Simple(kind) => kind, | ||
ErrorRepr::Message { kind, .. } => kind, | ||
ErrorRepr::Custom { kind, .. } => kind, | ||
ErrorRepr::Full { kind, .. } => kind, | ||
} | ||
} | ||
|
||
/// Consumes the `Error`, returning its inner error (if any). | ||
/// | ||
/// If this [`Error`] was constructed via [`Error::custom`] or [`Error::full`] | ||
/// then this function will return [`Ok`], otherwise it will return [`Err`]. | ||
pub fn into_inner(self) -> Result<Box<dyn std::error::Error + Send + Sync>, Self> { | ||
match self.repr { | ||
ErrorRepr::Custom { error, .. } => Ok(error), | ||
ErrorRepr::Full { error, .. } => Ok(error), | ||
_ => Err(self), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.repr) | ||
} | ||
} | ||
|
||
impl std::error::Error for Error { | ||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
match &self.repr { | ||
ErrorRepr::Custom { error, .. } => error.source(), | ||
ErrorRepr::Full { error, .. } => error.source(), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl SandboxErrorCode { | ||
pub(crate) fn custom<E>(self, error: E) -> Error | ||
where | ||
E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||
{ | ||
Error::custom(ErrorKind::Sandbox(self), error) | ||
} | ||
} | ||
|
||
impl From<SandboxErrorCode> for Error { | ||
fn from(code: SandboxErrorCode) -> Self { | ||
Error::simple(ErrorKind::Sandbox(code)) | ||
} | ||
} | ||
|
||
impl RpcErrorCode { | ||
pub(crate) fn message<T>(self, msg: T) -> Error | ||
where | ||
T: Into<Cow<'static, str>>, | ||
{ | ||
Error::message(ErrorKind::Rpc(self), msg) | ||
} | ||
|
||
pub(crate) fn custom<E>(self, error: E) -> Error | ||
where | ||
E: Into<Box<dyn std::error::Error + Send + Sync>>, | ||
{ | ||
Error::custom(ErrorKind::Rpc(self), error) | ||
} | ||
} | ||
|
||
impl From<RpcErrorCode> for Error { | ||
fn from(code: RpcErrorCode) -> Self { | ||
Error::simple(ErrorKind::Rpc(code)) | ||
} | ||
} |
Oops, something went wrong.