From 798b27ccb2621a42c33791a1a4fddf9bb343d17d Mon Sep 17 00:00:00 2001 From: JustTestingV Date: Sat, 20 Jan 2024 20:12:40 +0300 Subject: [PATCH] [xmpp] no panic! --- Cargo.lock | 1 + crates/projection-xmpp/src/lib.rs | 2 +- crates/proto-xmpp/Cargo.toml | 1 + crates/proto-xmpp/src/stream.rs | 7 ++++--- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c0ed647..c46c42f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1376,6 +1376,7 @@ dependencies = [ "anyhow", "assert_matches", "derive_more", + "lavina-core", "lazy_static", "quick-xml", "regex", diff --git a/crates/projection-xmpp/src/lib.rs b/crates/projection-xmpp/src/lib.rs index 9192092..9e852ca 100644 --- a/crates/projection-xmpp/src/lib.rs +++ b/crates/projection-xmpp/src/lib.rs @@ -83,7 +83,7 @@ pub async fn launch( let key = match read_one(&mut SyncBufReader::new(File::open(config.key)?))? { Some(PemItem::ECKey(k) | PemItem::PKCS8Key(k) | PemItem::RSAKey(k)) => PrivateKey(k), - _ => panic!("no keys in file"), + _ => return Err(fail("no keys in file")), }; let loaded_config = Arc::new(LoadedConfig { diff --git a/crates/proto-xmpp/Cargo.toml b/crates/proto-xmpp/Cargo.toml index 01fec80..ec43715 100644 --- a/crates/proto-xmpp/Cargo.toml +++ b/crates/proto-xmpp/Cargo.toml @@ -4,6 +4,7 @@ edition = "2021" version.workspace = true [dependencies] +lavina-core.workspace = true quick-xml.workspace = true lazy_static.workspace = true regex.workspace = true diff --git a/crates/proto-xmpp/src/stream.rs b/crates/proto-xmpp/src/stream.rs index 4d11039..40f5f5b 100644 --- a/crates/proto-xmpp/src/stream.rs +++ b/crates/proto-xmpp/src/stream.rs @@ -3,6 +3,7 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event}; use quick_xml::name::{Namespace, QName, ResolveResult}; use quick_xml::{NsReader, Writer}; use tokio::io::{AsyncBufRead, AsyncWrite}; +use lavina_core::prelude::fail; use super::skip_text; @@ -28,10 +29,10 @@ impl ClientStreamStart { if let Event::Start(e) = incoming { let (ns, local) = reader.resolve_element(e.name()); if ns != ResolveResult::Bound(Namespace(XMLNS.as_bytes())) { - return Err(panic!()); + return Err(fail("Invalid namespace for stream element")); } if local.into_inner() != b"stream" { - return Err(panic!()); + return Err(fail("Invalid local name for stream element")); } let mut to = None; let mut lang = None; @@ -64,7 +65,7 @@ impl ClientStreamStart { version: version.unwrap(), }) } else { - Err(panic!()) + Err(fail("Incoming message does not belong XML Start Event")) } } }