From e63ecc10aa426e3aba416fd05a3f568d719a79a3 Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sat, 21 Feb 2026 17:25:52 +0100 Subject: handshare and signalproxy/rpccall error handling --- src/message/handshake/clientinit.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/message/handshake/clientinit.rs') diff --git a/src/message/handshake/clientinit.rs b/src/message/handshake/clientinit.rs index 9d35243..3011821 100644 --- a/src/message/handshake/clientinit.rs +++ b/src/message/handshake/clientinit.rs @@ -63,13 +63,27 @@ impl HandshakeSerialize for ClientInit { } } -impl From for ClientInit { - fn from(mut input: VariantMap) -> Self { - ClientInit { - client_version: input.remove("ClientVersion").unwrap().try_into().unwrap(), - client_date: input.remove("ClientDate").unwrap().try_into().unwrap(), - client_features: input.remove("Features").unwrap().try_into().unwrap(), - feature_list: input.remove("FeatureList").unwrap().try_into().unwrap(), - } +impl TryFrom for ClientInit { + type Error = ProtocolError; + + fn try_from(mut input: VariantMap) -> Result { + Ok(ClientInit { + client_version: input + .remove("ClientVersion") + .ok_or_else(|| ProtocolError::MissingField("ClientVersion".to_string()))? + .try_into()?, + client_date: input + .remove("ClientDate") + .ok_or_else(|| ProtocolError::MissingField("ClientDate".to_string()))? + .try_into()?, + client_features: input + .remove("Features") + .ok_or_else(|| ProtocolError::MissingField("Features".to_string()))? + .try_into()?, + feature_list: input + .remove("FeatureList") + .ok_or_else(|| ProtocolError::MissingField("FeatureList".to_string()))? + .try_into()?, + }) } } -- cgit v1.2.3