Commit 38e62436d4

38e62436d4afca3ef75ad4d64b738804f429fd0a

parent: f247d1a0eb

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-30 14:46 UTC
committer: <strk@kbt.io>

fix: print concise join failures

Parse the join target once as a Matrix room ID or alias and report failed joins with the target plus the Matrix API display error.

This avoids exposing nested SDK Debug output in WeeChat.

Layout: unified · split

src/server.rs +33 −49
@@ -80,7 +80,8 @@ use matrix_sdk::{
8080 SyncStateEvent,
8181 },
8282 DeviceId, DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch,
83 OwnedDeviceId, OwnedMxcUri, OwnedRoomId, OwnedUserId, RoomId, UserId,
83 OwnedDeviceId, OwnedMxcUri, OwnedRoomId, OwnedRoomOrAliasId,
84 OwnedUserId, RoomId, UserId,
8485 },
8586 Client, Error,
8687};
@@ -214,59 +215,31 @@ impl MatrixServer {
214215 Rc::downgrade(&self.inner)
215216 }
216217
217 /// Join a Matrix room by ID or alias
218 /// Join a Matrix room by ID or alias.
218219 pub async fn join_room(&self, room_id_or_alias: String) {
219 let connection = if let Some(c) = self.connection() {
220 c
221 } else {
220 let Ok(room_id_or_alias) =
221 room_id_or_alias.parse::<OwnedRoomOrAliasId>()
222 else {
223 self.print_error("Invalid room ID or alias.");
224 return;
225 };
226
227 let Some(connection) = self.connection() else {
222228 self.print_error("Not connected. Please connect first.");
223229 return;
224230 };
225231
226232 self.print_network(&format!("Joining room {}...", room_id_or_alias));
227233
228 // Determine if it's a room ID or alias
229 let result = if room_id_or_alias.starts_with('!') {
230 // It's a room ID
231 use matrix_sdk::ruma::OwnedRoomId;
232 match room_id_or_alias.parse::<OwnedRoomId>() {
233 Ok(room_id) => {
234 let client = connection.client().clone();
235 connection.spawn(async move {
236 client.join_room_by_id(&room_id).await
237 }).await
238 }
239 Err(e) => {
240 self.print_error(&format!("Invalid room ID: {:?}", e));
241 return;
242 }
243 }
244 } else {
245 // It's a room alias (starts with # or we add it)
246 use matrix_sdk::ruma::OwnedRoomOrAliasId;
247 let alias = if room_id_or_alias.starts_with('#') {
248 room_id_or_alias.clone()
249 } else {
250 format!("#{}", room_id_or_alias)
251 };
252
253 match alias.parse::<OwnedRoomOrAliasId>() {
254 Ok(room_or_alias) => {
255 let client = connection.client().clone();
256 connection
257 .spawn(async move {
258 client
259 .join_room_by_id_or_alias(&room_or_alias, &[])
260 .await
261 })
262 .await
263 }
264 Err(e) => {
265 self.print_error(&format!("Invalid room alias: {:?}", e));
266 return;
267 }
268 }
269 };
234 let client = connection.client().clone();
235 let target = room_id_or_alias.to_string();
236 let result = connection
237 .spawn(async move {
238 client
239 .join_room_by_id_or_alias(&room_id_or_alias, &[])
240 .await
241 })
242 .await;
270243
271244 match result {
272245 Ok(room) => {
@@ -275,8 +248,12 @@ impl MatrixServer {
275248 room.room_id()
276249 ));
277250 }
278 Err(e) => {
279 self.print_error(&format!("Failed to join room: {:?}", e));
251 Err(error) => {
252 self.print_error(&format!(
253 "Failed to join {}: {}",
254 target,
255 format_join_error(&error)
256 ));
280257 }
281258 }
282259 }
@@ -485,6 +462,13 @@ impl MatrixServer {
485462 }
486463}
487464
465fn format_join_error(error: &Error) -> String {
466 error
467 .as_client_api_error()
468 .map(ToString::to_string)
469 .unwrap_or_else(|| error.to_string())
470}
471
488472impl Drop for MatrixServer {
489473 fn drop(&mut self) {
490474 // TODO close all the server buffers.