From 207832be432271b0b8f542653402dc8e2acac7bc Mon Sep 17 00:00:00 2001 From: StNicolay Date: Mon, 8 May 2023 19:12:50 +0300 Subject: [PATCH] Updated error message of unwrapping the Arc in import.rs and export.rs, now collection the file in export.rs into Vec instead of String --- src/handlers/commands/export.rs | 10 +++++++--- src/handlers/commands/import.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/handlers/commands/export.rs b/src/handlers/commands/export.rs index 137f841..1f2d203 100644 --- a/src/handlers/commands/export.rs +++ b/src/handlers/commands/export.rs @@ -6,7 +6,7 @@ use crate::{ }; use futures::TryStreamExt; use sea_orm::DatabaseConnection; -use serde_json::to_string_pretty; +use serde_json::to_vec_pretty; use std::sync::Arc; use teloxide::{adaptors::Throttle, prelude::*, types::InputFile}; use tokio::{sync::Mutex, task::spawn_blocking}; @@ -38,10 +38,14 @@ async fn get_master_pass( drop(master_pass); let mut accounts = match Arc::try_unwrap(accounts) { Ok(account) => account.into_inner(), - Err(_) => unreachable!(), + Err(_) => { + return Err(crate::Error::msg( + "Couldn't get accounts from Arc in export.rs", + )) + } }; accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name)); - let json = to_string_pretty(&User { accounts })?; + let json = to_vec_pretty(&User { accounts })?; let file = InputFile::memory(json).file_name("accounts.json"); bot.send_document(msg.chat.id, file) .reply_markup(deletion_markup()) diff --git a/src/handlers/commands/import.rs b/src/handlers/commands/import.rs index bd91ca9..5e5d109 100644 --- a/src/handlers/commands/import.rs +++ b/src/handlers/commands/import.rs @@ -49,7 +49,11 @@ async fn get_master_pass( drop(master_pass); let failed = match Arc::try_unwrap(failed) { Ok(accounts) => accounts.into_inner(), - Err(_) => unreachable!(), + Err(_) => { + return Err(crate::Error::msg( + "Couldn't get accounts from Arc in import.rs", + )) + } }; let message = if failed.is_empty() { "Success".to_owned() @@ -84,7 +88,7 @@ async fn get_document( } }; match document.file_name { - Some(ref name) if name.trim().ends_with(".json") => (), + Some(ref name) if name.trim_end().ends_with(".json") => (), _ => { bot.send_message(msg.chat.id, "Invalid file name") .reply_markup(deletion_markup())