forked from trinitrix/core
Fix(treewide): Replaced needless expect statements
This commit is contained in:
parent
ce59c504bd
commit
a30229b763
|
@ -39,29 +39,29 @@ impl Account {
|
|||
}
|
||||
|
||||
impl AccountsManager {
|
||||
pub fn new(config: Option<String>) -> Self {
|
||||
pub fn new(config: Option<String>) -> Result<Self> {
|
||||
return match config {
|
||||
Some(s) => {
|
||||
info!("Loading serialized AccountsManager");
|
||||
let accounts_data: AccountsData =
|
||||
serde_json::from_str(&s).expect("failed to deserialize json");
|
||||
serde_json::from_str(&s)?;
|
||||
let mut clients = Vec::new();
|
||||
clients.resize(accounts_data.accounts.len(), None);
|
||||
Self {
|
||||
Ok(Self {
|
||||
current_account: accounts_data.current_account,
|
||||
num_accounts: accounts_data.accounts.len() as u32,
|
||||
accounts: accounts_data.accounts,
|
||||
clients,
|
||||
}
|
||||
})
|
||||
}
|
||||
None => {
|
||||
info!("Creating empty AccountsManager");
|
||||
Self {
|
||||
Ok(Self {
|
||||
current_account: 0,
|
||||
num_accounts: 0,
|
||||
accounts: Vec::new(),
|
||||
clients: Vec::new(),
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -92,16 +92,20 @@ impl AccountsManager {
|
|||
.send()
|
||||
.await?;
|
||||
|
||||
let session = client.session().expect("failed to get session");
|
||||
let session = match client.session() {
|
||||
Some(s) => s,
|
||||
None => return Err(Error::msg("Failed to get session"))
|
||||
};
|
||||
|
||||
let name = match client.account().get_display_name().await? {
|
||||
Some(n) => n,
|
||||
None => return Err(Error::msg("Failed to get display name"))
|
||||
};
|
||||
|
||||
let account = Account {
|
||||
homeserver: homeserver.to_string(),
|
||||
id,
|
||||
name: client
|
||||
.account()
|
||||
.get_display_name()
|
||||
.await?
|
||||
.expect("failed to fetch display name"),
|
||||
name,
|
||||
session: session.clone(),
|
||||
sync_token: None,
|
||||
};
|
||||
|
@ -128,7 +132,11 @@ impl AccountsManager {
|
|||
error!("Tried to log in with an invalid account ID {}", account_id);
|
||||
return Err(Error::msg("Invalid account ID"));
|
||||
} else {
|
||||
self.get(account_id).expect("Account lookup failed")
|
||||
if let Some(a) = self.get(account_id) {
|
||||
a
|
||||
} else {
|
||||
return Err(Error::msg("Failed to get account"));
|
||||
}
|
||||
};
|
||||
|
||||
if self
|
||||
|
|
|
@ -29,27 +29,27 @@ impl Drop for App<'_> {
|
|||
}
|
||||
|
||||
impl App<'_> {
|
||||
pub fn new() -> Self {
|
||||
pub fn new() -> Result<Self> {
|
||||
let path: &std::path::Path = Path::new("userdata/accounts.json");
|
||||
let config = if path.exists() {
|
||||
info!("Reading account config (userdata/accounts.json)");
|
||||
Some(std::fs::read_to_string(path).expect("failed to read accounts config"))
|
||||
Some(std::fs::read_to_string(path)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let (channel_tx, channel_rx) = mpsc::channel(256);
|
||||
|
||||
Self {
|
||||
ui: ui::UI::new(),
|
||||
accounts_manager: AccountsManager::new(config),
|
||||
Ok(Self {
|
||||
ui: ui::UI::new()?,
|
||||
accounts_manager: AccountsManager::new(config)?,
|
||||
status: Status::new(None),
|
||||
|
||||
channel_tx,
|
||||
channel_rx,
|
||||
input_listener_killer: CancellationToken::new(),
|
||||
matrix_listener_killer: CancellationToken::new(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<()> {
|
||||
|
|
|
@ -6,7 +6,7 @@ mod ui;
|
|||
async fn main() -> anyhow::Result<()> {
|
||||
cli_log::init_cli_log!();
|
||||
|
||||
let mut app = app::App::new();
|
||||
let mut app = app::App::new()?;
|
||||
app.run().await?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -243,12 +243,12 @@ impl SetupUI<'_> {
|
|||
}
|
||||
|
||||
impl UI<'_> {
|
||||
pub fn new() -> Self {
|
||||
let stdout = terminal_prepare().expect("failed to prepare terminal");
|
||||
pub fn new() -> Result<Self> {
|
||||
let stdout = terminal_prepare()?;
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend).expect("failed to initialize terminal");
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
terminal.clear().expect("failed to clear screen");
|
||||
terminal.clear()?;
|
||||
|
||||
let mut message_compose = TextArea::default();
|
||||
message_compose.set_block(
|
||||
|
@ -259,14 +259,14 @@ impl UI<'_> {
|
|||
|
||||
info!("Initialized UI");
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
terminal,
|
||||
input_position: MainInputPosition::Rooms,
|
||||
rooms_state: ListState::default(),
|
||||
message_compose,
|
||||
cli: None,
|
||||
setup_ui: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn cycle_main_input_position(&mut self) {
|
||||
|
|
Loading…
Reference in New Issue