this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

collapse error enum into categories

+61 -42
+7
Cargo.lock
··· 2818 2818 "jacquard-oauth", 2819 2819 "keyring", 2820 2820 "onyx-lexicons", 2821 + "owo-colors", 2821 2822 "serde", 2822 2823 "serde_json", 2823 2824 "thiserror 2.0.18", ··· 2923 2924 "quote", 2924 2925 "syn 2.0.114", 2925 2926 ] 2927 + 2928 + [[package]] 2929 + name = "owo-colors" 2930 + version = "4.2.3" 2931 + source = "registry+https://github.com/rust-lang/crates.io-index" 2932 + checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" 2926 2933 2927 2934 [[package]] 2928 2935 name = "p256"
+1
Cargo.toml
··· 13 13 jacquard-oauth = { version = "0.9.6", features = ["browser-open", "loopback"] } 14 14 keyring = { version = "3.6.3", features = ["linux-native-sync-persistent", "apple-native", "windows-native", "crypto-rust", "vendored"] } 15 15 onyx-lexicons = { path = "crates/lexicons" } 16 + owo-colors = "4.2.3" 16 17 serde = "1.0.228" 17 18 serde_json = "1.0.149" 18 19 thiserror = "2.0.18"
+7 -7
src/auth.rs
··· 289 289 GenericSession::KeyringOAuth(session) => session 290 290 .send_http(request) 291 291 .await 292 - .map_err(|e| OnyxError::Identity(e.to_string())), 292 + .map_err(|e| OnyxError::Auth(e.to_string())), 293 293 GenericSession::FileOAuth(session) => session 294 294 .send_http(request) 295 295 .await 296 - .map_err(|e| OnyxError::Identity(e.to_string())), 296 + .map_err(|e| OnyxError::Auth(e.to_string())), 297 297 GenericSession::KeyringPassword(session) => session 298 298 .send_http(request) 299 299 .await 300 - .map_err(|e| OnyxError::Identity(e.to_string())), 300 + .map_err(|e| OnyxError::Auth(e.to_string())), 301 301 GenericSession::FilePassword(session) => session 302 302 .send_http(request) 303 303 .await 304 - .map_err(|e| OnyxError::Identity(e.to_string())), 304 + .map_err(|e| OnyxError::Auth(e.to_string())), 305 305 } 306 306 } 307 307 } ··· 645 645 let session = match self.auth_store.get_session()? { 646 646 Some(s) => s, 647 647 None => { 648 - return Err(OnyxError::AuthStore("not logged in".to_string())); 648 + return Err(OnyxError::Auth("not logged in".to_string())); 649 649 } 650 650 }; 651 651 ··· 710 710 let session = match self.auth_store.get_session()? { 711 711 Some(s) => s, 712 712 None => { 713 - return Err(OnyxError::AuthStore("not logged in".to_string())); 713 + return Err(OnyxError::Auth("not logged in".to_string())); 714 714 } 715 715 }; 716 716 ··· 732 732 if let Some(session) = session { 733 733 Ok(session) 734 734 } else { 735 - Err(OnyxError::AuthStore("not logged in".to_string())) 735 + Err(OnyxError::Auth("not logged in".to_string())) 736 736 } 737 737 } 738 738
+16 -31
src/error.rs
··· 21 21 22 22 #[derive(Debug, Error)] 23 23 pub enum OnyxError { 24 - #[error("auth store error: {0}")] 25 - AuthStore(String), 26 - 27 - #[error("session store error: {0}")] 28 - SessionStore(String), 24 + #[error("auth: {0}")] 25 + Auth(String), 29 26 30 - #[error("io error: {0}")] 27 + #[error("io: {0}")] 31 28 Io(String), 32 29 33 - #[error("serde error: {0}")] 34 - Serde(String), 35 - 36 - #[error("identity error: {0}")] 37 - Identity(String), 38 - 39 - #[error("oauth error: {0}")] 40 - OAuthError(String), 41 - 42 - #[error("client error: {0}")] 43 - ClientError(String), 30 + #[error("parse: {0}")] 31 + Parse(String), 44 32 45 - #[error("agent error: {0}")] 46 - AgentError(String), 47 - 48 - #[error("parser error: {0}")] 49 - ParserError(String), 50 - 51 - #[error(transparent)] 33 + #[error("unknown: {0}")] 52 34 Other(#[from] Box<dyn std::error::Error + Send + Sync>), 53 35 } 54 36 ··· 66 48 67 49 impl From<SessionStoreError> for OnyxError { 68 50 fn from(err: SessionStoreError) -> Self { 69 - OnyxError::SessionStore(err.to_string()) 51 + OnyxError::Auth(err.to_string()) 70 52 } 71 53 } 72 54 ··· 78 60 79 61 impl From<serde_json::Error> for OnyxError { 80 62 fn from(err: serde_json::Error) -> Self { 81 - OnyxError::Serde(err.to_string()) 63 + OnyxError::Parse(err.to_string()) 82 64 } 83 65 } 84 66 85 67 impl From<IdentityError> for OnyxError { 86 68 fn from(err: IdentityError) -> Self { 87 - OnyxError::Identity(err.to_string()) 69 + OnyxError::Other(err.to_string().into()) 88 70 } 89 71 } 90 72 91 73 impl From<OAuthError> for OnyxError { 92 74 fn from(err: OAuthError) -> Self { 93 - OnyxError::OAuthError(err.to_string()) 75 + OnyxError::Auth(err.to_string()) 94 76 } 95 77 } 96 78 97 79 impl From<ClientError> for OnyxError { 98 80 fn from(err: ClientError) -> Self { 99 - OnyxError::ClientError(err.to_string()) 81 + OnyxError::Other(err.to_string().into()) 100 82 } 101 83 } 102 84 103 85 impl From<AgentError> for OnyxError { 104 86 fn from(err: AgentError) -> Self { 105 - OnyxError::AgentError(err.to_string()) 87 + OnyxError::Other(err.to_string().into()) 106 88 } 107 89 } 108 90 109 91 impl From<ParserError> for OnyxError { 110 92 fn from(err: ParserError) -> Self { 111 - OnyxError::ParserError(err.to_string()) 93 + match err { 94 + ParserError::Io(e) => OnyxError::Io(e.to_string()), 95 + _ => OnyxError::Parse(err.to_string()), 96 + } 112 97 } 113 98 }
+28 -2
src/main.rs
··· 1 + use owo_colors::OwoColorize; 1 2 use serde::{Deserialize, Serialize}; 2 3 use std::path::PathBuf; 3 4 ··· 179 180 format!("v{}", env!("CARGO_PKG_VERSION")) 180 181 } 181 182 182 - #[tokio::main] 183 - async fn main() -> Result<(), OnyxError> { 183 + async fn run_onyx() -> Result<(), OnyxError> { 184 184 let mut matches = get_command().get_matches(); 185 185 let args = Args::from_arg_matches_mut(&mut matches).unwrap(); 186 186 ··· 275 275 276 276 Ok(()) 277 277 } 278 + 279 + fn print_error(e: &OnyxError) { 280 + println!("{} {}", "error:".red().bold(), e); 281 + } 282 + 283 + fn handle_error(e: OnyxError) { 284 + match e { 285 + OnyxError::Auth(_) => { 286 + print_error(&e); 287 + println!( 288 + "{} try logging in with '{}'", 289 + "hint:".green().bold(), 290 + "onyx auth login".cyan().bold() 291 + ); 292 + } 293 + _ => print_error(&e), 294 + } 295 + } 296 + 297 + #[tokio::main] 298 + async fn main() { 299 + if let Err(e) = run_onyx().await { 300 + handle_error(e); 301 + std::process::exit(1); 302 + } 303 + }
+2 -2
src/parser/error.rs
··· 2 2 3 3 #[derive(Debug, Error)] 4 4 pub enum ParserError { 5 - #[error("io error: {0}")] 5 + #[error("io: {0}")] 6 6 Io(#[from] std::io::Error), 7 7 8 - #[error("syntax error: {0}")] 8 + #[error("syntax: {0}")] 9 9 Syntax(String), 10 10 11 11 #[error("{0}")]