From 9bd8f5272f0fa86346802d7728a21db8edcbc760 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 15 Jan 2023 08:57:08 +0900 Subject: [PATCH] Define From for Error --- plume-models/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 7e424da8..1f39252f 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -24,6 +24,7 @@ use heck::ToUpperCamelCase; pub use lettre; pub use lettre::smtp; use once_cell::sync::Lazy; +use plume_common::activity_pub::PreferredUsernameError; use plume_common::activity_pub::{inbox::InboxError, request, sign, PreferredUsername}; use posts::PostEvent; use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder}; @@ -175,6 +176,13 @@ impl From for Error { } } +impl From for Error { + fn from(err: PreferredUsernameError) -> Error { + tracing::trace!("{:?}", err); + Error::InvalidValue + } +} + pub type Result = std::result::Result; /// Adds a function to a model, that returns the first @@ -349,13 +357,13 @@ pub enum Fqn { impl Fqn { pub fn new_local(username: String) -> Result { Ok(Self::Local( - PreferredUsername::new(username).map_err(|_| Error::InvalidValue)?, + PreferredUsername::new(username)?, )) } pub fn new_remote(username: String, domain: String) -> Result { Ok(Self::Remote( - PreferredUsername::new(username).map_err(|_| Error::InvalidValue)?, + PreferredUsername::new(username)?, domain, )) }