mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Provide better error message for M_UNKNOWN_TOKEN (#101)
This commit is contained in:
parent
46e081b1e4
commit
1e9b6cc271
2 changed files with 28 additions and 13 deletions
31
src/main.rs
31
src/main.rs
|
@ -28,6 +28,7 @@ use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use matrix_sdk::crypto::encrypt_room_key_export;
|
use matrix_sdk::crypto::encrypt_room_key_export;
|
||||||
|
use matrix_sdk::ruma::api::client::error::ErrorKind;
|
||||||
use matrix_sdk::ruma::OwnedUserId;
|
use matrix_sdk::ruma::OwnedUserId;
|
||||||
use modalkit::keybindings::InputBindings;
|
use modalkit::keybindings::InputBindings;
|
||||||
use rand::{distributions::Alphanumeric, Rng};
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
|
@ -745,7 +746,7 @@ async fn login(worker: &Requester, settings: &ApplicationSettings) -> IambResult
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_exit<T: Display, N>(v: T) -> N {
|
fn print_exit<T: Display, N>(v: T) -> N {
|
||||||
println!("{v}");
|
eprintln!("{v}");
|
||||||
process::exit(2);
|
process::exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,7 +848,9 @@ async fn login_upgrade(
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("* Syncing...");
|
println!("* Syncing...");
|
||||||
worker::do_first_sync(&worker.client, store).await;
|
worker::do_first_sync(&worker.client, store)
|
||||||
|
.await
|
||||||
|
.map_err(IambError::from)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -859,7 +862,9 @@ async fn login_normal(
|
||||||
) -> IambResult<()> {
|
) -> IambResult<()> {
|
||||||
println!("* Logging in for {}...", settings.profile.user_id);
|
println!("* Logging in for {}...", settings.profile.user_id);
|
||||||
login(worker, settings).await?;
|
login(worker, settings).await?;
|
||||||
worker::do_first_sync(&worker.client, store).await;
|
worker::do_first_sync(&worker.client, store)
|
||||||
|
.await
|
||||||
|
.map_err(IambError::from)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,12 +883,22 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> {
|
||||||
let store = Arc::new(AsyncMutex::new(store));
|
let store = Arc::new(AsyncMutex::new(store));
|
||||||
worker.init(store.clone());
|
worker.init(store.clone());
|
||||||
|
|
||||||
if let Some((keydir, pass)) = import_keys {
|
let res = if let Some((keydir, pass)) = import_keys {
|
||||||
login_upgrade(keydir, pass, &worker, &settings, &store)
|
login_upgrade(keydir, pass, &worker, &settings, &store).await
|
||||||
.await
|
|
||||||
.unwrap_or_else(print_exit);
|
|
||||||
} else {
|
} else {
|
||||||
login_normal(&worker, &settings, &store).await.unwrap_or_else(print_exit);
|
login_normal(&worker, &settings, &store).await
|
||||||
|
};
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Err(UIError::Application(IambError::Matrix(e))) => {
|
||||||
|
if let Some(ErrorKind::UnknownToken { .. }) = e.client_api_error_kind() {
|
||||||
|
print_exit("Server did not recognize our API token; did you log out from this session elsewhere?")
|
||||||
|
} else {
|
||||||
|
print_exit(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => print_exit(e),
|
||||||
|
Ok(()) => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_tty() {
|
fn restore_tty() {
|
||||||
|
|
|
@ -79,6 +79,7 @@ use matrix_sdk::{
|
||||||
Client,
|
Client,
|
||||||
ClientBuildError,
|
ClientBuildError,
|
||||||
DisplayName,
|
DisplayName,
|
||||||
|
Error as MatrixError,
|
||||||
RoomMemberships,
|
RoomMemberships,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -538,7 +539,7 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) {
|
pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) -> Result<(), MatrixError> {
|
||||||
// Perform an initial, lazily-loaded sync.
|
// Perform an initial, lazily-loaded sync.
|
||||||
let mut room = RoomEventFilter::default();
|
let mut room = RoomEventFilter::default();
|
||||||
room.lazy_load_options = LazyLoadOptions::Enabled { include_redundant_members: false };
|
room.lazy_load_options = LazyLoadOptions::Enabled { include_redundant_members: false };
|
||||||
|
@ -551,10 +552,7 @@ pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) {
|
||||||
|
|
||||||
let settings = SyncSettings::new().filter(filter.into());
|
let settings = SyncSettings::new().filter(filter.into());
|
||||||
|
|
||||||
if let Err(e) = client.sync_once(settings).await {
|
client.sync_once(settings).await?;
|
||||||
tracing::error!(err = e.to_string(), "Failed to perform initial sync; will retry later");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate sync_info with our initial set of rooms/dms/spaces.
|
// Populate sync_info with our initial set of rooms/dms/spaces.
|
||||||
refresh_rooms(client, store).await;
|
refresh_rooms(client, store).await;
|
||||||
|
@ -572,6 +570,8 @@ pub async fn do_first_sync(client: &Client, store: &AsyncProgramStore) {
|
||||||
let room_id = room.as_ref().0.room_id().to_owned();
|
let room_id = room.as_ref().0.room_id().to_owned();
|
||||||
need_load.insert(room_id, Need::MESSAGES);
|
need_load.insert(room_id, Need::MESSAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue