From 024eb3df4a0786a92033baea123aa779998cdc28 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sun, 22 Feb 2026 14:06:16 +0100 Subject: NetworkList and signalproxy objects error handling --- .../signalproxy/objects/ignorelistmanager.rs | 70 ++++++++++++---------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'src/message/signalproxy/objects/ignorelistmanager.rs') diff --git a/src/message/signalproxy/objects/ignorelistmanager.rs b/src/message/signalproxy/objects/ignorelistmanager.rs index 4697611..5a38fd0 100644 --- a/src/message/signalproxy/objects/ignorelistmanager.rs +++ b/src/message/signalproxy/objects/ignorelistmanager.rs @@ -1,7 +1,7 @@ use crate::{ - error::ProtocolError, message::{Class, Syncable}, primitive::Variant, + ProtocolError, Result, }; use libquassel_derive::{sync, NetworkList, NetworkMap}; @@ -51,7 +51,7 @@ impl IgnoreListManager { scope_rule, is_active, }: IgnoreListItem, - ) { + ) -> Result<()> { sync!( "requestAddIgnoreListItem", [ @@ -66,15 +66,15 @@ impl IgnoreListManager { ) } - pub fn request_remove_ignore_list_item(&self, rule: String) { + pub fn request_remove_ignore_list_item(&self, rule: String) -> Result<()> { sync!("requestRemoveIgnoreListItem", [rule]) } - pub fn request_toggle_ignore_rule(&self, rule: String) { + pub fn request_toggle_ignore_rule(&self, rule: String) -> Result<()> { sync!("requestToggleIgnoreRule", [rule]) } - pub fn add_ignore_list_item(&mut self, item: IgnoreListItem) { + pub fn add_ignore_list_item(&mut self, item: IgnoreListItem) -> Result<()> { #[cfg(feature = "server")] sync!( "addIgnoreListItem", @@ -87,14 +87,16 @@ impl IgnoreListManager { item.scope_rule.clone(), item.is_active ] - ); + )?; if self.ignore_list_item(&item.ignore_rule).is_none() { self.ignore_list.push(item) }; + + Ok(()) } - pub fn remove_ignore_list_item(&mut self, rule: &str) { + pub fn remove_ignore_list_item(&mut self, rule: &str) -> Result<()> { if let Some(position) = self .ignore_list .iter() @@ -104,22 +106,28 @@ impl IgnoreListManager { }; #[cfg(feature = "server")] - sync!("removeIgnoreListItem", [rule]) + return sync!("removeIgnoreListItem", [rule]); + + #[cfg(feature = "client")] + return Ok(()); } - pub fn toggle_ignore_rule(&mut self, rule: &str) { + pub fn toggle_ignore_rule(&mut self, rule: &str) -> Result<()> { if let Some(item) = self.ignore_list_item_mut(rule) { item.is_active = !item.is_active } #[cfg(feature = "server")] - sync!("toggleIgnoreRule", [rule]) + return sync!("toggleIgnoreRule", [rule]); + + #[cfg(feature = "client")] + return Ok(()); } } #[cfg(feature = "client")] impl crate::message::StatefulSyncableClient for IgnoreListManager { - fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError> + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<()> where Self: Sized, { @@ -135,21 +143,20 @@ impl crate::message::StatefulSyncableClient for IgnoreListManager { }), "removeIgnoreListItem" => { let rule: String = get_param!(msg); - self.remove_ignore_list_item(&rule); + self.remove_ignore_list_item(&rule) } "toggleIgnoreRule" => { let rule: String = get_param!(msg); - self.toggle_ignore_rule(&rule); + self.toggle_ignore_rule(&rule) } - _ => (), + _ => Ok(()), } - Ok(()) } } #[cfg(feature = "server")] impl crate::message::StatefulSyncableServer for IgnoreListManager { - fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError> + fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<()> where Self: Sized, { @@ -165,15 +172,14 @@ impl crate::message::StatefulSyncableServer for IgnoreListManager { }), "requestRemoveIgnoreListItem" => { let rule: String = get_param!(msg); - self.remove_ignore_list_item(&rule); + self.remove_ignore_list_item(&rule) } "requestToggleIgnoreRule" => { let rule: String = get_param!(msg); - self.toggle_ignore_rule(&rule); + self.toggle_ignore_rule(&rule) } - _ => (), + _ => Ok(()), } - Ok(()) } } @@ -221,7 +227,7 @@ impl From for Variant { impl TryFrom for IgnoreType { type Error = ProtocolError; - fn try_from(value: Variant) -> Result { + fn try_from(value: Variant) -> Result { let i: i32 = value.try_into()?; Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } @@ -234,14 +240,14 @@ impl From for i32 { } impl TryFrom for IgnoreType { - type Error = &'static str; + type Error = ProtocolError; - fn try_from(value: i32) -> Result { + fn try_from(value: i32) -> Result { match value { 0x00 => Ok(IgnoreType::SenderIgnore), 0x01 => Ok(IgnoreType::MessageIgnore), 0x02 => Ok(IgnoreType::CtcpIgnore), - _ => Err("no matching IgnoreType found"), + err => Err(ProtocolError::UnknownIgnoreType(err)), } } } @@ -263,7 +269,7 @@ impl From for Variant { impl TryFrom for StrictnessType { type Error = ProtocolError; - fn try_from(value: Variant) -> Result { + fn try_from(value: Variant) -> Result { let i: i32 = value.try_into()?; Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } @@ -276,14 +282,14 @@ impl From for i32 { } impl TryFrom for StrictnessType { - type Error = &'static str; + type Error = ProtocolError; - fn try_from(value: i32) -> Result { + fn try_from(value: i32) -> Result { match value { 0x00 => Ok(StrictnessType::UnmatchedStrictness), 0x01 => Ok(StrictnessType::SoftStrictness), 0x02 => Ok(StrictnessType::HardStrictness), - _ => Err("no matching StrictnessType found"), + err => Err(ProtocolError::UnknownStrictnessType(err)), } } } @@ -305,7 +311,7 @@ impl From for Variant { impl TryFrom for ScopeType { type Error = ProtocolError; - fn try_from(value: Variant) -> Result { + fn try_from(value: Variant) -> Result { let i: i32 = value.try_into()?; Self::try_from(i).map_err(|_| ProtocolError::WrongVariant) } @@ -318,14 +324,14 @@ impl From for i32 { } impl TryFrom for ScopeType { - type Error = &'static str; + type Error = ProtocolError; - fn try_from(value: i32) -> Result { + fn try_from(value: i32) -> Result { match value { 0x00 => Ok(ScopeType::GlobalScope), 0x01 => Ok(ScopeType::NetworkScope), 0x02 => Ok(ScopeType::ChannelScope), - _ => Err("no matching ScopeType found"), + err => Err(ProtocolError::UnknownScopeType(err)), } } } -- cgit v1.2.3 title='2025-02-25 00:09:27 +0100'>2025-02-25Use MsgId in VariantTobias Deiminger-20/+37 2025-02-25Add MsgId as Rust typeTobias Deiminger-0/+56 Up to now it was handled implicitely in Variant::UserType. Making it an explicit type allows to centralize the i32/i64 cfg dependency and to use the type for arguments in signalproxy::objects functions. 2025-02-24added session manager comments and log messageMax Audron-1/+3 2025-02-23add identity syncable to SessionManagerMax Audron-1/+8 2025-02-23add syncables for IrcUserMax Audron-2/+53 2025-02-23move network config to it's own file and impl it's syncMax Audron-23/+84 2025-02-23add basic network syncablesMax Audron-39/+420 2025-02-23clean up unused_import and unused_variables a bitMax Audron-2/+8 2025-02-23fix server feature errorsMax Audron-28/+23 2025-02-23fix ircchannel and maplist network representationMax Audron-154/+137 2025-02-22replace deprecated failure crate with thiserrorMax Audron-278/+194 this changes the public API in that all our methods now return a proper ProtocolError crate. Needed change anyways to properly deal with all our errors in the long run. Will still need to do a pass through the crate to remove all existing unwraps where it makes sense. 2025-02-22update dependencies and fix errorsMax Audron-508/+332 2025-02-22update flakeMax Audron-94/+117 2024-05-22add todos to readmeMax Audron-16/+35