this repo has no description
at main 104 lines 2.4 kB view raw
1use jacquard::{ 2 client::{AgentError, SessionStoreError}, 3 error::ClientError, 4 types::{string::AtStrError, uri::UriError}, 5}; 6use jacquard_identity::resolver::IdentityError; 7use jacquard_oauth::error::OAuthError; 8use thiserror::Error; 9 10use crate::parser::ParserError; 11 12pub trait MapErrExt<T> { 13 fn map_session_store_err(self) -> Result<T, SessionStoreError>; 14} 15 16impl<T> MapErrExt<T> for Result<T, keyring::Error> { 17 fn map_session_store_err(self) -> Result<T, SessionStoreError> { 18 self.map_err(|e| SessionStoreError::Other(Box::new(e))) 19 } 20} 21 22#[derive(Debug, Error)] 23pub enum OnyxError { 24 #[error("auth: {0}")] 25 Auth(String), 26 27 #[error("io: {0}")] 28 Io(String), 29 30 #[error("parse: {0}")] 31 Parse(String), 32 33 #[error("{0}")] 34 Other(#[from] Box<dyn std::error::Error + Send + Sync>), 35} 36 37impl From<AtStrError> for OnyxError { 38 fn from(value: AtStrError) -> Self { 39 Self::Other(Box::new(value)) 40 } 41} 42 43impl From<tokio::sync::TryLockError> for OnyxError { 44 fn from(value: tokio::sync::TryLockError) -> Self { 45 Self::Other(Box::new(value)) 46 } 47} 48 49impl From<SessionStoreError> for OnyxError { 50 fn from(err: SessionStoreError) -> Self { 51 OnyxError::Auth(err.to_string()) 52 } 53} 54 55impl From<std::io::Error> for OnyxError { 56 fn from(err: std::io::Error) -> Self { 57 OnyxError::Io(err.to_string()) 58 } 59} 60 61impl From<serde_json::Error> for OnyxError { 62 fn from(err: serde_json::Error) -> Self { 63 OnyxError::Parse(err.to_string()) 64 } 65} 66 67impl From<IdentityError> for OnyxError { 68 fn from(err: IdentityError) -> Self { 69 OnyxError::Other(err.to_string().into()) 70 } 71} 72 73impl From<OAuthError> for OnyxError { 74 fn from(err: OAuthError) -> Self { 75 OnyxError::Auth(err.to_string()) 76 } 77} 78 79impl From<ClientError> for OnyxError { 80 fn from(err: ClientError) -> Self { 81 OnyxError::Other(err.to_string().into()) 82 } 83} 84 85impl From<AgentError> for OnyxError { 86 fn from(err: AgentError) -> Self { 87 OnyxError::Other(err.to_string().into()) 88 } 89} 90 91impl From<UriError> for OnyxError { 92 fn from(err: UriError) -> Self { 93 OnyxError::Other(err.to_string().into()) 94 } 95} 96 97impl From<ParserError> for OnyxError { 98 fn from(err: ParserError) -> Self { 99 match err { 100 ParserError::Io(e) => OnyxError::Io(e.to_string()), 101 _ => OnyxError::Parse(err.to_string()), 102 } 103 } 104}