Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
75
fork

Configure Feed

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

propagate hickory init error

instead of panicking

phil a6bf7d38 95c60ce3

+16 -15
+16 -15
who-am-i/src/oauth.rs
··· 46 46 } 47 47 48 48 #[derive(Debug, Error)] 49 - #[error(transparent)] 50 - pub struct AuthSetupError(#[from] atrium_oauth::Error); 49 + pub enum AuthSetupError { 50 + #[error("failed to intiialize atrium client: {0}")] 51 + AtriumClientError(atrium_oauth::Error), 52 + #[error("failed to initialize hickory dns resolver: {0}")] 53 + HickoryResolverError(hickory_resolver::ResolveError), 54 + } 51 55 52 56 #[derive(Debug, Error)] 53 57 #[error(transparent)] ··· 93 97 http_client: http_client.clone(), 94 98 }) 95 99 }; 100 + let dns_txt_resolver = 101 + HickoryDnsTxtResolver::new().map_err(AuthSetupError::HickoryResolverError)?; 96 102 let client_config = OAuthClientConfig { 97 103 client_metadata: AtprotoLocalhostClientMetadata { 98 104 redirect_uris: Some(vec![String::from("http://127.0.0.1:9997/authorized")]), ··· 102 108 resolver: OAuthResolverConfig { 103 109 did_resolver: did_resolver(), 104 110 handle_resolver: AtprotoHandleResolver::new(AtprotoHandleResolverConfig { 105 - dns_txt_resolver: HickoryDnsTxtResolver::default(), 111 + dns_txt_resolver, 106 112 http_client: Arc::clone(&http_client), 107 113 }), 108 114 authorization_server_metadata: Default::default(), ··· 112 118 session_store: MemorySessionStore::default(), 113 119 }; 114 120 115 - let client = OAuthClient::new(client_config)?; 121 + let client = OAuthClient::new(client_config).map_err(AuthSetupError::AtriumClientError)?; 116 122 117 123 Ok(Self { 118 124 client: Arc::new(client), ··· 185 191 } 186 192 } 187 193 188 - pub struct HickoryDnsTxtResolver { 189 - resolver: TokioResolver, 190 - } 194 + pub struct HickoryDnsTxtResolver(TokioResolver); 191 195 192 - impl Default for HickoryDnsTxtResolver { 193 - fn default() -> Self { 194 - Self { 195 - resolver: TokioResolver::builder_tokio() 196 - .expect("failed to create resolver") 197 - .build(), 198 - } 196 + impl HickoryDnsTxtResolver { 197 + fn new() -> Result<Self, hickory_resolver::ResolveError> { 198 + let resolver = TokioResolver::builder_tokio()?.build(); 199 + Ok(Self(resolver)) 199 200 } 200 201 } 201 202 ··· 205 206 query: &str, 206 207 ) -> core::result::Result<Vec<String>, Box<dyn std::error::Error + Send + Sync>> { 207 208 Ok(self 208 - .resolver 209 + .0 209 210 .txt_lookup(query) 210 211 .await? 211 212 .iter()