aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Audron <me@audron.dev>2026-02-21 17:48:06 +0100
committerMax Audron <me@audron.dev>2026-02-21 17:48:06 +0100
commitcc542048e369dda0a773e1e3a4601dc7d20ff16a (patch)
treeee3a23a88c0cb39cf222b871932636a2c912dd92 /src
parenthandshare and signalproxy/rpccall error handling (diff)
Syncable trait error handling
Diffstat (limited to 'src')
-rw-r--r--src/frame/tests.rs4
-rw-r--r--src/message/signalproxy/initrequest.rs2
-rw-r--r--src/message/signalproxy/mod.rs35
-rw-r--r--src/message/signalproxy/objects/aliasmanager.rs3
-rw-r--r--src/message/signalproxy/objects/buffersyncer.rs7
-rw-r--r--src/message/signalproxy/objects/bufferviewconfig.rs12
-rw-r--r--src/message/signalproxy/objects/bufferviewmanager.rs6
-rw-r--r--src/message/signalproxy/objects/certmanager.rs5
-rw-r--r--src/message/signalproxy/objects/coreinfo.rs9
-rw-r--r--src/message/signalproxy/objects/highlightrulemanager.rs18
-rw-r--r--src/message/signalproxy/objects/identity.rs3
-rw-r--r--src/message/signalproxy/objects/ignorelistmanager.rs48
-rw-r--r--src/message/signalproxy/objects/ircchannel.rs8
-rw-r--r--src/message/signalproxy/objects/ircuser.rs3
-rw-r--r--src/message/signalproxy/objects/network.rs20
-rw-r--r--src/message/signalproxy/objects/networkconfig.rs6
-rw-r--r--src/message/signalproxy/rpccall/client.rs5
-rw-r--r--src/message/signalproxy/syncmessage.rs1
-rw-r--r--src/primitive/bufferid.rs1
-rw-r--r--src/primitive/variant.rs2
-rw-r--r--src/session.rs43
21 files changed, 152 insertions, 89 deletions
diff --git a/src/frame/tests.rs b/src/frame/tests.rs
index 5029ea3..4ae5e1a 100644
--- a/src/frame/tests.rs
+++ b/src/frame/tests.rs
@@ -149,7 +149,9 @@ pub fn read_multi_frame() {
#[test]
pub fn read_single_frame_compressed() {
let io = FramedRead::new(
- Builder::new().read(b"\x78\x9c\x63\x60\x60\xe0\x4c\x4c\x4a\x4e\x49\x4d\x4b\xcf\xc8\x04\x00\x11\xec\x03\x97").build(),
+ Builder::new()
+ .read(b"\x78\x9c\x63\x60\x60\xe0\x4c\x4c\x4a\x4e\x49\x4d\x4b\xcf\xc8\x04\x00\x11\xec\x03\x97")
+ .build(),
QuasselCodec::builder().compression(true).new_codec(),
);
pin_mut!(io);
diff --git a/src/message/signalproxy/initrequest.rs b/src/message/signalproxy/initrequest.rs
index ad6a3f2..1aea1c9 100644
--- a/src/message/signalproxy/initrequest.rs
+++ b/src/message/signalproxy/initrequest.rs
@@ -35,5 +35,3 @@ impl Deserialize for InitRequest {
))
}
}
-
-
diff --git a/src/message/signalproxy/mod.rs b/src/message/signalproxy/mod.rs
index 90cf7e5..7e36017 100644
--- a/src/message/signalproxy/mod.rs
+++ b/src/message/signalproxy/mod.rs
@@ -114,26 +114,30 @@ pub trait StatefulSyncableServer: Syncable + translation::NetworkMap
where
Variant: From<<Self as translation::NetworkMap>::Item>,
{
- fn sync(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
match msg.slot_name.as_str() {
"requestUpdate" => {
- StatefulSyncableServer::request_update(self, msg.params.pop().unwrap().try_into().unwrap())
+ StatefulSyncableServer::request_update(
+ self,
+ msg.params.pop().ok_or(ProtocolError::WrongVariant)?.try_into()?,
+ )?;
+ Ok(())
}
_ => StatefulSyncableServer::sync_custom(self, msg),
}
}
#[allow(unused_mut)]
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
#[allow(clippy::match_single_binding)]
match msg.slot_name.as_str() {
- _ => (),
+ _ => Ok(()),
}
}
@@ -146,43 +150,54 @@ where
}
/// Server -> Client: Update the whole object with received data
- fn request_update(&mut self, mut param: <Self as translation::NetworkMap>::Item)
+ fn request_update(
+ &mut self,
+ mut param: <Self as translation::NetworkMap>::Item,
+ ) -> Result<(), ProtocolError>
where
Self: Sized,
{
*self = Self::from_network_map(&mut param);
+ Ok(())
}
}
/// Methods for a Stateful Syncable object on the server side.
pub trait StatefulSyncableClient: Syncable + translation::NetworkMap {
- fn sync(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
match msg.slot_name.as_str() {
- "update" => StatefulSyncableClient::update(self, msg.params.pop().unwrap().try_into().unwrap()),
+ "update" => {
+ StatefulSyncableClient::update(
+ self,
+ msg.params.pop().ok_or(ProtocolError::WrongVariant)?.try_into()?,
+ )?;
+ Ok(())
+ }
_ => StatefulSyncableClient::sync_custom(self, msg),
}
}
#[allow(unused_mut)]
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
#[allow(clippy::match_single_binding)]
match msg.slot_name.as_str() {
- _ => (),
+ _ => Ok(()),
}
}
/// Client -> Server: Update the whole object with received data
- fn update(&mut self, mut param: <Self as translation::NetworkMap>::Item)
+ fn update(&mut self, mut param: <Self as translation::NetworkMap>::Item) -> Result<(), ProtocolError>
where
Self: Sized,
{
*self = Self::from_network_map(&mut param);
+ Ok(())
}
/// Server -> Client: Update the whole object with received data
diff --git a/src/message/signalproxy/objects/aliasmanager.rs b/src/message/signalproxy/objects/aliasmanager.rs
index 02add49..7b98426 100644
--- a/src/message/signalproxy/objects/aliasmanager.rs
+++ b/src/message/signalproxy/objects/aliasmanager.rs
@@ -40,7 +40,7 @@ impl StatefulSyncableClient for AliasManager {}
#[cfg(feature = "server")]
impl StatefulSyncableServer for AliasManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -50,6 +50,7 @@ impl StatefulSyncableServer for AliasManager {
)),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/buffersyncer.rs b/src/message/signalproxy/objects/buffersyncer.rs
index b2e12c4..22a435d 100644
--- a/src/message/signalproxy/objects/buffersyncer.rs
+++ b/src/message/signalproxy/objects/buffersyncer.rs
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use crate::{
+ error::ProtocolError,
message::{Class, Syncable},
primitive::{BufferId, MessageType, MsgId},
};
@@ -135,7 +136,7 @@ impl BufferSyncer {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for BufferSyncer {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -153,12 +154,13 @@ impl crate::message::StatefulSyncableClient for BufferSyncer {
"setMarkerLine" => self.set_marker_line(get_param!(msg), get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for BufferSyncer {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -174,6 +176,7 @@ impl crate::message::StatefulSyncableServer for BufferSyncer {
"requestSetMarkerLine" => self.set_marker_line(get_param!(msg), get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/bufferviewconfig.rs b/src/message/signalproxy/objects/bufferviewconfig.rs
index 286e83a..ade5bc5 100644
--- a/src/message/signalproxy/objects/bufferviewconfig.rs
+++ b/src/message/signalproxy/objects/bufferviewconfig.rs
@@ -15,7 +15,11 @@ pub struct BufferViewConfig {
pub buffers: Vec<BufferId>,
#[network(rename = "RemovedBuffers", network = "list", variant = "VariantList")]
pub removed_buffers: Vec<BufferId>,
- #[network(rename = "TemporarilyRemovedBuffers", network = "list", variant = "VariantList")]
+ #[network(
+ rename = "TemporarilyRemovedBuffers",
+ network = "list",
+ variant = "VariantList"
+ )]
pub temporarily_removed_buffers: Vec<BufferId>,
#[network(rename = "bufferViewId", default, skip)]
@@ -124,7 +128,7 @@ impl BufferViewConfig {
#[cfg(feature = "client")]
impl StatefulSyncableClient for BufferViewConfig {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -144,12 +148,13 @@ impl StatefulSyncableClient for BufferViewConfig {
}
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl StatefulSyncableServer for BufferViewConfig {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -182,6 +187,7 @@ impl StatefulSyncableServer for BufferViewConfig {
"setSortAlphabetically" => self.sort_alphabetically = msg.params.remove(0).try_into().unwrap(),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/bufferviewmanager.rs b/src/message/signalproxy/objects/bufferviewmanager.rs
index 1097ade..6d2d593 100644
--- a/src/message/signalproxy/objects/bufferviewmanager.rs
+++ b/src/message/signalproxy/objects/bufferviewmanager.rs
@@ -80,7 +80,7 @@ impl BufferViewManager {
#[cfg(feature = "client")]
impl StatefulSyncableClient for BufferViewManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -93,12 +93,13 @@ impl StatefulSyncableClient for BufferViewManager {
}
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl StatefulSyncableServer for BufferViewManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -124,6 +125,7 @@ impl StatefulSyncableServer for BufferViewManager {
}
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/certmanager.rs b/src/message/signalproxy/objects/certmanager.rs
index a518b7b..ab78500 100644
--- a/src/message/signalproxy/objects/certmanager.rs
+++ b/src/message/signalproxy/objects/certmanager.rs
@@ -1,6 +1,6 @@
use libquassel_derive::{NetworkList, NetworkMap};
-use crate::message::{Syncable, Class};
+use crate::message::{Class, Syncable};
#[allow(unused_imports)]
use crate::primitive::Variant;
@@ -30,7 +30,7 @@ impl CertManager {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for CertManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -39,6 +39,7 @@ impl crate::message::StatefulSyncableClient for CertManager {
"setSslKey" => self.set_ssl_key(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/coreinfo.rs b/src/message/signalproxy/objects/coreinfo.rs
index 5036abd..8dba602 100644
--- a/src/message/signalproxy/objects/coreinfo.rs
+++ b/src/message/signalproxy/objects/coreinfo.rs
@@ -22,7 +22,7 @@ impl CoreInfo {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for CoreInfo {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -31,6 +31,7 @@ impl crate::message::StatefulSyncableClient for CoreInfo {
"setCoreData" => self.set_core_data(CoreData::from_network_map(&mut get_param!(msg))),
_ => (),
}
+ Ok(())
}
/// Not Implemented
@@ -44,10 +45,14 @@ impl crate::message::StatefulSyncableClient for CoreInfo {
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for CoreInfo {
/// Not Implemented
- fn request_update(&mut self, mut _param: <CoreInfo as NetworkMap>::Item)
+ fn request_update(
+ &mut self,
+ mut _param: <CoreInfo as NetworkMap>::Item,
+ ) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/highlightrulemanager.rs b/src/message/signalproxy/objects/highlightrulemanager.rs
index 7accb17..9af0b4c 100644
--- a/src/message/signalproxy/objects/highlightrulemanager.rs
+++ b/src/message/signalproxy/objects/highlightrulemanager.rs
@@ -1,5 +1,6 @@
use libquassel_derive::{sync, NetworkList, NetworkMap};
+use crate::error::ProtocolError;
use crate::message::Class;
#[allow(unused_imports)]
@@ -135,7 +136,7 @@ impl HighlightRuleManager {
#[cfg(feature = "client")]
impl StatefulSyncableClient for HighlightRuleManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -156,12 +157,13 @@ impl StatefulSyncableClient for HighlightRuleManager {
"setNicksCaseSensitive" => self.set_nicks_case_sensitive(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl StatefulSyncableServer for HighlightRuleManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -182,6 +184,7 @@ impl StatefulSyncableServer for HighlightRuleManager {
"requestSetNicksCaseSensitive" => self.set_nicks_case_sensitive(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
@@ -223,11 +226,12 @@ impl From<HighlightNickType> for Variant {
}
}
-// TODO error handling
-impl From<Variant> for HighlightNickType {
- fn from(value: Variant) -> Self {
- #[allow(clippy::unnecessary_fallible_conversions)]
- HighlightNickType::try_from(value).unwrap()
+impl TryFrom<Variant> for HighlightNickType {
+ type Error = ProtocolError;
+
+ fn try_from(value: Variant) -> Result<Self, Self::Error> {
+ let i: i32 = value.try_into()?;
+ Self::try_from(i).map_err(|_| ProtocolError::WrongVariant)
}
}
diff --git a/src/message/signalproxy/objects/identity.rs b/src/message/signalproxy/objects/identity.rs
index ec7d9b4..e745a9e 100644
--- a/src/message/signalproxy/objects/identity.rs
+++ b/src/message/signalproxy/objects/identity.rs
@@ -96,7 +96,7 @@ impl Identity {
#[cfg(feature = "client")]
impl StatefulSyncableClient for Identity {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -123,6 +123,7 @@ impl StatefulSyncableClient for Identity {
"setRealName" => self.set_real_name(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/ignorelistmanager.rs b/src/message/signalproxy/objects/ignorelistmanager.rs
index b97ca77..4697611 100644
--- a/src/message/signalproxy/objects/ignorelistmanager.rs
+++ b/src/message/signalproxy/objects/ignorelistmanager.rs
@@ -1,4 +1,5 @@
use crate::{
+ error::ProtocolError,
message::{Class, Syncable},
primitive::Variant,
};
@@ -118,7 +119,7 @@ impl IgnoreListManager {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for IgnoreListManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -142,12 +143,13 @@ impl crate::message::StatefulSyncableClient for IgnoreListManager {
}
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for IgnoreListManager {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -171,6 +173,7 @@ impl crate::message::StatefulSyncableServer for IgnoreListManager {
}
_ => (),
}
+ Ok(())
}
}
@@ -201,8 +204,6 @@ pub struct IgnoreListItem {
//////////////////////////////////////
-use num_traits::{FromPrimitive, ToPrimitive};
-
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive)]
pub enum IgnoreType {
@@ -213,19 +214,22 @@ pub enum IgnoreType {
impl From<IgnoreType> for Variant {
fn from(value: IgnoreType) -> Self {
- Variant::i32(value.to_i32().unwrap())
+ Variant::i32(value as i32)
}
}
-impl From<Variant> for IgnoreType {
- fn from(value: Variant) -> Self {
- IgnoreType::from_i32(value.try_into().unwrap()).unwrap()
+impl TryFrom<Variant> for IgnoreType {
+ type Error = ProtocolError;
+
+ fn try_from(value: Variant) -> Result<Self, Self::Error> {
+ let i: i32 = value.try_into()?;
+ Self::try_from(i).map_err(|_| ProtocolError::WrongVariant)
}
}
impl From<IgnoreType> for i32 {
fn from(value: IgnoreType) -> Self {
- value.to_i32().unwrap()
+ value as i32
}
}
@@ -252,19 +256,22 @@ pub enum StrictnessType {
impl From<StrictnessType> for Variant {
fn from(value: StrictnessType) -> Self {
- Variant::i32(value.to_i32().unwrap())
+ Variant::i32(value as i32)
}
}
-impl From<Variant> for StrictnessType {
- fn from(value: Variant) -> Self {
- StrictnessType::from_i32(value.try_into().unwrap()).unwrap()
+impl TryFrom<Variant> for StrictnessType {
+ type Error = ProtocolError;
+
+ fn try_from(value: Variant) -> Result<Self, Self::Error> {
+ let i: i32 = value.try_into()?;
+ Self::try_from(i).map_err(|_| ProtocolError::WrongVariant)
}
}
impl From<StrictnessType> for i32 {
fn from(value: StrictnessType) -> Self {
- value.to_i32().unwrap()
+ value as i32
}
}
@@ -291,19 +298,22 @@ pub enum ScopeType {
impl From<ScopeType> for Variant {
fn from(value: ScopeType) -> Self {
- Variant::i32(value.to_i32().unwrap())
+ Variant::i32(value as i32)
}
}
-impl From<Variant> for ScopeType {
- fn from(value: Variant) -> Self {
- ScopeType::from_i32(value.try_into().unwrap()).unwrap()
+impl TryFrom<Variant> for ScopeType {
+ type Error = ProtocolError;
+
+ fn try_from(value: Variant) -> Result<Self, Self::Error> {
+ let i: i32 = value.try_into()?;
+ Self::try_from(i).map_err(|_| ProtocolError::WrongVariant)
}
}
impl From<ScopeType> for i32 {
fn from(value: ScopeType) -> Self {
- value.to_i32().unwrap()
+ value as i32
}
}
diff --git a/src/message/signalproxy/objects/ircchannel.rs b/src/message/signalproxy/objects/ircchannel.rs
index 9648210..ef42d3b 100644
--- a/src/message/signalproxy/objects/ircchannel.rs
+++ b/src/message/signalproxy/objects/ircchannel.rs
@@ -172,7 +172,7 @@ impl IrcChannel {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for IrcChannel {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -195,6 +195,7 @@ impl crate::message::StatefulSyncableClient for IrcChannel {
"setUserModes" => self.set_user_modes(get_param!(msg), get_param!(msg)),
_ => (),
}
+ Ok(())
}
/// Not Implemented for this type
@@ -209,7 +210,10 @@ impl crate::message::StatefulSyncableClient for IrcChannel {
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for IrcChannel {
/// Not Implemented for this type
- fn request_update(&mut self, _param: <IrcChannel as crate::message::NetworkMap>::Item)
+ fn request_update(
+ &mut self,
+ _param: <IrcChannel as crate::message::NetworkMap>::Item,
+ ) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
diff --git a/src/message/signalproxy/objects/ircuser.rs b/src/message/signalproxy/objects/ircuser.rs
index 3b807ed..8529405 100644
--- a/src/message/signalproxy/objects/ircuser.rs
+++ b/src/message/signalproxy/objects/ircuser.rs
@@ -111,7 +111,7 @@ impl IrcUser {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for IrcUser {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -142,6 +142,7 @@ impl crate::message::StatefulSyncableClient for IrcUser {
"updateHostmask" => self.update_hostmask(get_param!(msg)),
_ => unimplemented!(),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/network.rs b/src/message/signalproxy/objects/network.rs
index 3d2ee8b..d256f67 100644
--- a/src/message/signalproxy/objects/network.rs
+++ b/src/message/signalproxy/objects/network.rs
@@ -192,7 +192,7 @@ impl Syncable for Network {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for Network {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -223,9 +223,10 @@ impl crate::message::StatefulSyncableClient for Network {
"setMessageRateDelay" => self.network_info.set_msg_rate_message_delay(get_param!(msg)),
"setMyNick" => self.set_my_nick(get_param!(msg)),
"setNetworkName" => self.network_info.set_network_name(get_param!(msg)),
- "setNetworkInfo" => self.set_network_info(NetworkInfo::from_network_map(
- &mut VariantMap::try_from(msg.params.remove(0)).unwrap(),
- )),
+ "setNetworkInfo" => {
+ let mut map = VariantMap::try_from(msg.params.remove(0))?;
+ self.set_network_info(NetworkInfo::from_network_map(&mut map));
+ }
"setPerform" => self.network_info.set_perform(get_param!(msg)),
"setRejoinChannels" => self.network_info.set_rejoin_channels(get_param!(msg)),
"setSaslAccount" => self.network_info.set_sasl_account(get_param!(msg)),
@@ -254,23 +255,26 @@ impl crate::message::StatefulSyncableClient for Network {
"setUseSasl" => self.network_info.set_use_sasl(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for Network {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
match msg.slot_name.as_str() {
"requestConnect" => self.connect(),
"requestDisconnect" => self.disconnect(),
- "requestSetNetworkInfo" => self.set_network_info(NetworkInfo::from_network_map(
- &mut VariantMap::try_from(msg.params.remove(0)).unwrap(),
- )),
+ "requestSetNetworkInfo" => {
+ let mut map = VariantMap::try_from(msg.params.remove(0))?;
+ self.set_network_info(NetworkInfo::from_network_map(&mut map));
+ }
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/objects/networkconfig.rs b/src/message/signalproxy/objects/networkconfig.rs
index c4f5397..6268a69 100644
--- a/src/message/signalproxy/objects/networkconfig.rs
+++ b/src/message/signalproxy/objects/networkconfig.rs
@@ -28,7 +28,7 @@ impl Syncable for NetworkConfig {
#[cfg(feature = "client")]
impl crate::message::StatefulSyncableClient for NetworkConfig {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -43,12 +43,13 @@ impl crate::message::StatefulSyncableClient for NetworkConfig {
"setStandardCtcp" => self.set_standard_ctcp(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
#[cfg(feature = "server")]
impl crate::message::StatefulSyncableServer for NetworkConfig {
- fn sync_custom(&mut self, mut msg: crate::message::SyncMessage)
+ fn sync_custom(&mut self, mut msg: crate::message::SyncMessage) -> Result<(), crate::error::ProtocolError>
where
Self: Sized,
{
@@ -63,5 +64,6 @@ impl crate::message::StatefulSyncableServer for NetworkConfig {
"requestSetStandardCtcp" => self.set_standard_ctcp(get_param!(msg)),
_ => (),
}
+ Ok(())
}
}
diff --git a/src/message/signalproxy/rpccall/client.rs b/src/message/signalproxy/rpccall/client.rs
index 13653b9..bf35cb5 100644
--- a/src/message/signalproxy/rpccall/client.rs
+++ b/src/message/signalproxy/rpccall/client.rs
@@ -13,10 +13,7 @@ impl RpcCallType for KickClient {
const DIRECTION: Direction = Direction::ClientToServer;
fn to_network(&self) -> Result<Vec<crate::primitive::Variant>, crate::ProtocolError> {
- Ok(vec![
- Variant::ByteArray(Self::NAME.to_string()),
- self.id.into(),
- ])
+ Ok(vec![Variant::ByteArray(Self::NAME.to_string()), self.id.into()])
}
fn from_network(
diff --git a/src/message/signalproxy/syncmessage.rs b/src/message/signalproxy/syncmessage.rs
index d38ea20..5a7163b 100644
--- a/src/message/signalproxy/syncmessage.rs
+++ b/src/message/signalproxy/syncmessage.rs
@@ -122,4 +122,3 @@ impl Deserialize for SyncMessage {
))
}
}
-
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs
index 7d9b2bc..9d780c6 100644
--- a/src/primitive/bufferid.rs
+++ b/src/primitive/bufferid.rs
@@ -56,7 +56,6 @@ impl NetworkList for Vec<BufferId> {
input.iter().map(|b| b.try_into().unwrap()).collect()
}
}
-
#[cfg(test)]
mod tests {
diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs
index 14a96a7..f39d405 100644
--- a/src/primitive/variant.rs
+++ b/src/primitive/variant.rs
@@ -68,7 +68,7 @@ impl TryFrom<Variant> for String {
match input {
Variant::String(value) => Ok(value),
Variant::ByteArray(value) => Ok(value),
- _ => Err(ProtocolError::UnknownVariant)
+ _ => Err(ProtocolError::UnknownVariant),
}
}
}
diff --git a/src/session.rs b/src/session.rs
index 6b00916..c30551e 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -13,6 +13,7 @@ use crate::message::StatefulSyncableServer;
use log::{debug, error, warn};
use crate::{
+ error::ProtocolError,
message::{
objects::{Types, *},
Class, InitData, SessionInit, SyncMessage, Syncable,
@@ -56,7 +57,7 @@ pub trait SessionManager {
fn network_config(&mut self) -> &mut NetworkConfig;
/// Handles an incoming [SyncMessage] and passes it on to the correct destination Object.
- fn sync(&mut self, msg: SyncMessage)
+ fn sync(&mut self, msg: SyncMessage) -> Result<(), ProtocolError>
where
Self: Sized,
{
@@ -64,36 +65,41 @@ pub trait SessionManager {
Class::AliasManager => self.alias_manager().sync(msg),
Class::BacklogManager => self.backlog_manager().sync(msg),
Class::BufferSyncer => self.buffer_syncer().sync(msg),
- Class::BufferViewConfig => (),
+ Class::BufferViewConfig => Ok(()),
Class::BufferViewManager => self.buffer_view_manager().sync(msg),
Class::CoreInfo => self.core_info().sync(msg),
// Synced via CoreInfo
- Class::CoreData => (),
+ Class::CoreData => Ok(()),
Class::HighlightRuleManager => self.highlight_rule_manager().sync(msg),
Class::Identity => {
let identity_id: i32 = msg.object_name.parse().unwrap();
if let Some(identity) = self.identity(identity_id as usize) {
- identity.sync(msg);
+ identity.sync(msg)?;
} else {
warn!("could not find identity with id: {:?}", identity_id);
}
+ Ok(())
}
Class::IgnoreListManager => self.ignore_list_manager().sync(msg),
Class::CertManager => self.cert_manager().sync(msg),
Class::Network => {
let id: i32 = msg.object_name.parse().unwrap();
if let Some(network) = self.network(id) {
- network.sync(msg)
+ network.sync(msg)?;
}
+ Ok(())
}
// NetworkInfo does not receive SyncMessages directly but via Network
- Class::NetworkInfo => (),
+ Class::NetworkInfo => Ok(()),
Class::NetworkConfig => match msg.object_name.as_ref() {
"GlobalNetworkConfig" => self.network_config().sync(msg),
- _ => error!(
- "received network config sync with unknown object name: {}",
- msg.object_name
- ),
+ _ => {
+ error!(
+ "received network config sync with unknown object name: {}",
+ msg.object_name
+ );
+ Ok(())
+ }
},
Class::IrcChannel => {
let mut object_name = msg.object_name.split('/');
@@ -120,6 +126,7 @@ pub trait SessionManager {
mode,
get_param!(msg),
);
+ Ok(())
}
"removeChannelMode" => {
let mut msg = msg.clone();
@@ -131,13 +138,13 @@ pub trait SessionManager {
.get_mut(channel)
.unwrap()
.remove_channel_mode(mode_type, mode, get_param!(msg));
+ Ok(())
}
_ => network.irc_channels.get_mut(channel).unwrap().sync(msg.clone()),
- }
+ }?;
}
- } else {
- warn!("Could not find Network {:?}", network_id)
}
+ Ok(())
}
Class::IrcUser => {
let mut object_name = msg.object_name.split('/');
@@ -148,17 +155,19 @@ pub trait SessionManager {
if let Some(network) = self.network(network_id) {
if let Some(user) = network.irc_users.get_mut(user) {
- user.sync(msg);
+ user.sync(msg)?;
// TODO we probably need to deal with the quit here?
// and remove the user from the network
} else {
warn!("Could not find IrcUser {} in Network {:?}", user, network_id)
}
- } else {
- warn!("Could not find Network {:?}", network_id)
}
+ Ok(())
+ }
+ Class::Unknown => {
+ warn!("received unknown object syncmessage: {:?}", msg);
+ Ok(())
}
- Class::Unknown => warn!("received unknown object syncmessage: {:?}", msg),
}
}