From f74d34f188a98e2bc5d1938aee2060c758d4b22e Mon Sep 17 00:00:00 2001 From: StNicolay Date: Mon, 5 Jun 2023 10:57:47 +0300 Subject: [PATCH] Updated get_accounts to handle the errors of concatenating the accounts --- src/commands/get_accounts.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/commands/get_accounts.rs b/src/commands/get_accounts.rs index 11392cd..3eaaa5a 100644 --- a/src/commands/get_accounts.rs +++ b/src/commands/get_accounts.rs @@ -1,6 +1,6 @@ use crate::{errors::NoUserInfo, markups::deletion_markup}; use entity::prelude::*; -use futures::TryStreamExt; +use futures::{future, TryStreamExt}; use sea_orm::DatabaseConnection; use std::fmt::Write; use teloxide::{adaptors::Throttle, prelude::*, types::ParseMode}; @@ -13,7 +13,7 @@ pub async fn get_accounts( ) -> crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let mut account_names = Account::get_names(user_id, &db, true).await?; - let mut result = match account_names.try_next().await? { + let mut text = match account_names.try_next().await? { Some(name) => format!("Accounts:\n`{name}`"), None => { bot.send_message(msg.chat.id, "No accounts found") @@ -23,12 +23,13 @@ pub async fn get_accounts( } }; account_names + .map_err(crate::Error::from) .try_for_each(|name| { - write!(result, "\n`{name}`").unwrap(); - async { Ok(()) } + let result = write!(text, "\n`{name}`").map_err(Into::into); + future::ready(result) }) .await?; - bot.send_message(msg.chat.id, result) + bot.send_message(msg.chat.id, text) .parse_mode(ParseMode::MarkdownV2) .reply_markup(deletion_markup()) .await?;