diff --git a/src/app.rs b/src/app.rs index b8b5ebe..2045854 100644 --- a/src/app.rs +++ b/src/app.rs @@ -19,7 +19,7 @@ use std::collections::VecDeque; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::RwLock; -use color_eyre::eyre::{Result, WrapErr}; +use color_eyre::eyre::{eyre, Result, WrapErr}; use crossterm::event::KeyEvent; use futures::stream::FuturesUnordered; use futures::{FutureExt, StreamExt}; @@ -68,15 +68,19 @@ impl App { tokio::spawn(async move { let server_name = conf.user_id.server_name(); let user_dir = datadir.join(conf.user_id.to_string()); + std::fs::create_dir_all(&user_dir) + .with_context(|| format!("Could not create {}", user_dir.display()))?; // If there is at least one device state for that user, use it. Otherwise, // generate a random device id let device_dir = std::fs::read_dir(&user_dir) - .unwrap_or_else(|e| panic!("Could not read user dir: {}", e)) + .with_context(|| format!("Could not read {}", user_dir.display()))? .next() - .map(|dir_entry| { - dir_entry - .unwrap_or_else(|e| panic!("Could not read entry in {}: {}", user_dir.display(), e)) - .path() + .and_then(|dir_entry| match dir_entry { + Ok(dir_entry) => Some(dir_entry.path()), + Err(e) => { + tracing::error!("Could not read entry in {}: {}", user_dir.display(), e); + None + }, }) .unwrap_or_else(|| user_dir.join(matrix_sdk::ruma::DeviceId::new().as_str())); // Extract device id from the path @@ -85,7 +89,7 @@ impl App { .file_name() .expect("empty path to state store") .to_str() - .expect("device id is not valid UTF8"); + .ok_or_else(|| eyre!("device id in {} is not valid UTF8", device_dir.display()))?; let client = matrix_sdk::Client::builder() .server_name(server_name) .sqlite_store( @@ -103,6 +107,12 @@ impl App { .send() .await .with_context(|| format!("Could not login as {}", conf.user_id))?; + tracing::info!( + "Logged in as {}", + client + .user_id() + .ok_or_else(|| eyre!("Unexpectedly not logged in as {}", conf.user_id))?, + ); Ok::<_, color_eyre::eyre::Report>(client) }) });