From a52495ff9883e093dd09dff1a3a2d1521bb99533 Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Thu, 13 Oct 2022 15:43:43 +0200 Subject: [PATCH 1/5] add custom error handling --- src/error_manager.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 9 ++++----- src/trash_manager.rs | 14 ++++++++------ test/a.txt | 0 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 src/error_manager.rs create mode 100644 test/a.txt diff --git a/src/error_manager.rs b/src/error_manager.rs new file mode 100644 index 0000000..0bba888 --- /dev/null +++ b/src/error_manager.rs @@ -0,0 +1,46 @@ +use core::fmt; +use std::{error::Error, fmt::format}; + +use colored::Colorize; + +#[derive(Debug)] +pub enum RmtError { + InvalidNumberOfArguments(usize), + InvalidDirFlags { + folder_name: String, + element_in_folder: usize, + }, + InvalidFolderFlags { + folder_name: String, + }, + InvalidElementName { + element_name: String, + is_force_flags: bool, + }, +} + +impl RmtError { + fn error_message(&self) -> String { + match self { + RmtError::InvalidNumberOfArguments(args_number) => format!( + "The number of arguments ({}) is not valid.", + args_number.to_string().red().bold(), + ), + RmtError::InvalidDirFlags { folder_name, element_in_folder } => format!("You cannot delete {} folder with the {} flags because there is {} elements inside, you should use {} flags instead.", folder_name.red().bold(), "-d".red().bold().green(), element_in_folder.to_string().red().bold(), "-r".green().bold()), + _ => String::from("") + } + } + + fn default_help_message() -> String + { + format!("Use the {} option to get more details on how to use {}.", "rmt --help".bold().green(), "rmt".bold()) + } +} + +impl fmt::Display for RmtError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}: {}\n{}", "Error".red().bold(), self.error_message(), RmtError::default_help_message()) + } +} + +impl Error for RmtError {} diff --git a/src/main.rs b/src/main.rs index 0f30d16..c402625 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ pub mod config; pub mod config_manager; pub mod data_manager; pub mod display_manager; +pub mod error_manager; pub mod input_manager; pub mod structure_manager; pub mod trash_item; @@ -11,6 +12,8 @@ use arguments_manager::ArgumentsManager; use clap::Parser; use colored::Colorize; +use crate::error_manager::RmtError; + fn main() { let is_test = false; let arguments_manager = ArgumentsManager::parse(); @@ -21,11 +24,7 @@ fn main() { && !arguments_manager.is_trash_display && !arguments_manager.is_trash_info { - println!( - "{}\nYou should use {}", - "The arguments are not valid.".red().bold(), - "rmt --help".green().bold() - ); + println!("{}", RmtError::InvalidNumberOfArguments(0)); return; } diff --git a/src/trash_manager.rs b/src/trash_manager.rs index 0592fe3..4391a41 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -1,5 +1,6 @@ use crate::arguments_manager::ArgumentsManager; use crate::display_manager; +use crate::error_manager::RmtError; use crate::structure_manager::{self, get_element_name, get_element_path, get_home_directory_path}; use crate::{ config::Config, data_manager, structure_manager::get_trash_directory_path, @@ -38,12 +39,13 @@ pub fn add_element_to_trash( && !arguments_manager.is_recursive) || (element_in_dir > 0 && !arguments_manager.is_recursive) { - println!( - "Cannot delete the folder {} without the {} option or {} (for an empty folder)", - element_name.green().bold(), - "-r".bold().green(), - "-d".bold().green() - ); + // println!( + // "Cannot delete the folder {} without the {} option or {} (for an empty folder)", + // element_name.green().bold(), + // "-r".bold().green(), + // "-d".bold().green() + // ); + println!("{}", RmtError::InvalidDirFlags { folder_name: element_name.to_string(), element_in_folder: element_in_dir }); return; } } diff --git a/test/a.txt b/test/a.txt new file mode 100644 index 0000000..e69de29 From a651e4146d223144f4a7eee6179dd90faa50335f Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Thu, 13 Oct 2022 18:48:52 +0200 Subject: [PATCH 2/5] add custom error messages --- src/error_manager.rs | 29 ++++++++++++++++++++-------- src/trash_manager.rs | 45 ++++++++++++++++++++++++-------------------- test/a.txt | 0 3 files changed, 46 insertions(+), 28 deletions(-) delete mode 100644 test/a.txt diff --git a/src/error_manager.rs b/src/error_manager.rs index 0bba888..1db86d4 100644 --- a/src/error_manager.rs +++ b/src/error_manager.rs @@ -1,5 +1,5 @@ use core::fmt; -use std::{error::Error, fmt::format}; +use std::{error::Error}; use colored::Colorize; @@ -10,12 +10,14 @@ pub enum RmtError { folder_name: String, element_in_folder: usize, }, - InvalidFolderFlags { + InvalidFillFolderFlags { + folder_name: String, + }, + InvalidEmptyFolderFlags { folder_name: String, }, InvalidElementName { element_name: String, - is_force_flags: bool, }, } @@ -27,19 +29,30 @@ impl RmtError { args_number.to_string().red().bold(), ), RmtError::InvalidDirFlags { folder_name, element_in_folder } => format!("You cannot delete {} folder with the {} flags because there is {} elements inside, you should use {} flags instead.", folder_name.red().bold(), "-d".red().bold().green(), element_in_folder.to_string().red().bold(), "-r".green().bold()), - _ => String::from("") + RmtError::InvalidEmptyFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} or {} flags.", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), + RmtError::InvalidFillFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} flags (do no use {} flags because your directory isn't empty).", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), + RmtError::InvalidElementName { element_name} => format!("you cannot destroy your {} because it doesn't exist (use the {} option to stop getting this warning).", element_name.red().bold(), "-f".green().bold()) } } - fn default_help_message() -> String - { - format!("Use the {} option to get more details on how to use {}.", "rmt --help".bold().green(), "rmt".bold()) + fn default_help_message() -> String { + format!( + "Use the {} option to get more details on how to use {}.", + "rmt --help".bold().green(), + "rmt".bold() + ) } } impl fmt::Display for RmtError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}: {}\n{}", "Error".red().bold(), self.error_message(), RmtError::default_help_message()) + write!( + f, + "{}: {}\n{}", + "Error".red().bold(), + self.error_message(), + RmtError::default_help_message().italic() + ) } } diff --git a/src/trash_manager.rs b/src/trash_manager.rs index 4391a41..11409c4 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -29,38 +29,38 @@ pub fn add_element_to_trash( element_name: &str, is_test: bool, arguments_manager: &ArgumentsManager, -) { +) -> Result<(), RmtError> { let mut element_path = match abspath(element_name) { Some(path) => { if Path::new(&path).is_dir() { let element_in_dir = fs::read_dir(&path).unwrap().count(); - if (element_in_dir == 0 + if element_in_dir == 0 && !arguments_manager.is_empty_dir - && !arguments_manager.is_recursive) - || (element_in_dir > 0 && !arguments_manager.is_recursive) + && !arguments_manager.is_recursive { - // println!( - // "Cannot delete the folder {} without the {} option or {} (for an empty folder)", - // element_name.green().bold(), - // "-r".bold().green(), - // "-d".bold().green() - // ); - println!("{}", RmtError::InvalidDirFlags { folder_name: element_name.to_string(), element_in_folder: element_in_dir }); - return; + return Err(RmtError::InvalidEmptyFolderFlags { + folder_name: element_name.to_string(), + }); + } else if element_in_dir > 0 && arguments_manager.is_empty_dir { + return Err(RmtError::InvalidDirFlags { + folder_name: element_name.to_string(), + element_in_folder: element_in_dir, + }); + } else if element_in_dir > 0 && !arguments_manager.is_recursive { + return Err(RmtError::InvalidFillFolderFlags { + folder_name: element_name.to_string(), + }); } } path } None => { if arguments_manager.is_force { - return; + return Ok(()); } - println!( - "Unable to delete {}: No such file or folder (use {} to remove warnings)", - element_name.green().bold(), - "-f".green().bold() - ); - return; + return Err(RmtError::InvalidElementName { + element_name: element_name.to_string(), + }); } }; @@ -121,6 +121,7 @@ pub fn add_element_to_trash( element_name.green().bold() ); } + Ok(()) } pub fn add_all_elements_to_trash( @@ -143,7 +144,11 @@ pub fn add_all_elements_to_trash( let message = format!("Are you sure to delete {} ?", path.bold().green()); if !arguments_manager.confirmation_always || display_manager::get_user_validation(&message) { - add_element_to_trash(connection, config, path, is_test, arguments_manager); + if let Err(rmt_error) = + add_element_to_trash(connection, config, path, is_test, arguments_manager) + { + println!("{}", rmt_error); + } } } } diff --git a/test/a.txt b/test/a.txt deleted file mode 100644 index e69de29..0000000 From a26bac29d5b23fb7c08d121566345be5793875eb Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Thu, 13 Oct 2022 18:55:01 +0200 Subject: [PATCH 3/5] add arguments error --- src/error_manager.rs | 22 +++++++++++----------- src/main.rs | 4 ++-- src/trash_manager.rs | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/error_manager.rs b/src/error_manager.rs index 1db86d4..a7d582b 100644 --- a/src/error_manager.rs +++ b/src/error_manager.rs @@ -1,10 +1,10 @@ use core::fmt; -use std::{error::Error}; +use std::error::Error; use colored::Colorize; #[derive(Debug)] -pub enum RmtError { +pub enum RmtArgumentErrors { InvalidNumberOfArguments(usize), InvalidDirFlags { folder_name: String, @@ -21,17 +21,17 @@ pub enum RmtError { }, } -impl RmtError { +impl RmtArgumentErrors { fn error_message(&self) -> String { match self { - RmtError::InvalidNumberOfArguments(args_number) => format!( + RmtArgumentErrors::InvalidNumberOfArguments(args_number) => format!( "The number of arguments ({}) is not valid.", args_number.to_string().red().bold(), ), - RmtError::InvalidDirFlags { folder_name, element_in_folder } => format!("You cannot delete {} folder with the {} flags because there is {} elements inside, you should use {} flags instead.", folder_name.red().bold(), "-d".red().bold().green(), element_in_folder.to_string().red().bold(), "-r".green().bold()), - RmtError::InvalidEmptyFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} or {} flags.", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), - RmtError::InvalidFillFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} flags (do no use {} flags because your directory isn't empty).", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), - RmtError::InvalidElementName { element_name} => format!("you cannot destroy your {} because it doesn't exist (use the {} option to stop getting this warning).", element_name.red().bold(), "-f".green().bold()) + RmtArgumentErrors::InvalidDirFlags { folder_name, element_in_folder } => format!("You cannot delete {} folder with the {} flags because there is {} elements inside, you should use {} flags instead.", folder_name.red().bold(), "-d".red().bold().green(), element_in_folder.to_string().red().bold(), "-r".green().bold()), + RmtArgumentErrors::InvalidEmptyFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} or {} flags.", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), + RmtArgumentErrors::InvalidFillFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} flags (do no use {} flags because your directory isn't empty).", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()), + RmtArgumentErrors::InvalidElementName { element_name} => format!("you cannot destroy your {} because it doesn't exist (use the {} option to stop getting this warning).", element_name.red().bold(), "-f".green().bold()) } } @@ -44,16 +44,16 @@ impl RmtError { } } -impl fmt::Display for RmtError { +impl fmt::Display for RmtArgumentErrors { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "{}: {}\n{}", "Error".red().bold(), self.error_message(), - RmtError::default_help_message().italic() + RmtArgumentErrors::default_help_message().italic() ) } } -impl Error for RmtError {} +impl Error for RmtArgumentErrors {} diff --git a/src/main.rs b/src/main.rs index c402625..ded551f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use arguments_manager::ArgumentsManager; use clap::Parser; use colored::Colorize; -use crate::error_manager::RmtError; +use crate::error_manager::RmtArgumentErrors; fn main() { let is_test = false; @@ -24,7 +24,7 @@ fn main() { && !arguments_manager.is_trash_display && !arguments_manager.is_trash_info { - println!("{}", RmtError::InvalidNumberOfArguments(0)); + println!("{}", RmtArgumentErrors::InvalidNumberOfArguments(0)); return; } diff --git a/src/trash_manager.rs b/src/trash_manager.rs index 11409c4..de7c0ae 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -1,6 +1,6 @@ use crate::arguments_manager::ArgumentsManager; use crate::display_manager; -use crate::error_manager::RmtError; +use crate::error_manager::RmtArgumentErrors; use crate::structure_manager::{self, get_element_name, get_element_path, get_home_directory_path}; use crate::{ config::Config, data_manager, structure_manager::get_trash_directory_path, @@ -29,7 +29,7 @@ pub fn add_element_to_trash( element_name: &str, is_test: bool, arguments_manager: &ArgumentsManager, -) -> Result<(), RmtError> { +) -> Result<(), RmtArgumentErrors> { let mut element_path = match abspath(element_name) { Some(path) => { if Path::new(&path).is_dir() { @@ -38,16 +38,16 @@ pub fn add_element_to_trash( && !arguments_manager.is_empty_dir && !arguments_manager.is_recursive { - return Err(RmtError::InvalidEmptyFolderFlags { + return Err(RmtArgumentErrors::InvalidEmptyFolderFlags { folder_name: element_name.to_string(), }); } else if element_in_dir > 0 && arguments_manager.is_empty_dir { - return Err(RmtError::InvalidDirFlags { + return Err(RmtArgumentErrors::InvalidDirFlags { folder_name: element_name.to_string(), element_in_folder: element_in_dir, }); } else if element_in_dir > 0 && !arguments_manager.is_recursive { - return Err(RmtError::InvalidFillFolderFlags { + return Err(RmtArgumentErrors::InvalidFillFolderFlags { folder_name: element_name.to_string(), }); } @@ -58,7 +58,7 @@ pub fn add_element_to_trash( if arguments_manager.is_force { return Ok(()); } - return Err(RmtError::InvalidElementName { + return Err(RmtArgumentErrors::InvalidElementName { element_name: element_name.to_string(), }); } From f52275068bb3a6add4c0a5975902b918f0d2984a Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Thu, 13 Oct 2022 20:10:33 +0200 Subject: [PATCH 4/5] add database errors --- src/{error_manager.rs => argument_errors.rs} | 0 src/database_errors.rs | 52 ++++++++++++++++++++ src/main.rs | 5 +- src/trash_manager.rs | 2 +- 4 files changed, 56 insertions(+), 3 deletions(-) rename src/{error_manager.rs => argument_errors.rs} (100%) create mode 100644 src/database_errors.rs diff --git a/src/error_manager.rs b/src/argument_errors.rs similarity index 100% rename from src/error_manager.rs rename to src/argument_errors.rs diff --git a/src/database_errors.rs b/src/database_errors.rs new file mode 100644 index 0000000..cff16c3 --- /dev/null +++ b/src/database_errors.rs @@ -0,0 +1,52 @@ +use core::fmt; +use std::error::Error; + +use colored::Colorize; + +use crate::trash_item::{TrashItem}; + +#[derive(Debug)] +pub enum RmtDataBaseErrors { + DataBaseCreation, + SelectAllElements, + GetCellElement(u8), + DeleteElementById(i32), + InsertTrashItem(TrashItem), + DeleteAllElement + +} + +impl RmtDataBaseErrors { + fn error_message(&self) -> String { + match self { + RmtDataBaseErrors::DataBaseCreation => "Impossible to create the database.".to_string(), + RmtDataBaseErrors::SelectAllElements => "Impossible to select all the elements.".to_string(), + RmtDataBaseErrors::GetCellElement(index) => format!("Impossible to retrieve the cell with index {}.", index.to_string().red().bold()), + RmtDataBaseErrors::DeleteElementById(id) => format!("Impossible to delete the element at index {}.", id.to_string().red().bold()), + RmtDataBaseErrors::InsertTrashItem(trash_item) => format!("Impossible to insert the trashItem {}.", trash_item.to_string().red().bold()), + RmtDataBaseErrors::DeleteAllElement => "Impossible to delete all elements.".to_string(), + } + } + + fn default_help_message() -> String { + format!( + "If you haven't touched the {} file yourself, please open an issue on: {} with as many details as possible.", + ".trash_rmt".red().bold(), + "https://github.com/AmineZouitine/rmt.rs".bold().green() + ) + } +} + +impl fmt::Display for RmtDataBaseErrors { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "{}: {}\n{}", + "Error".red().bold(), + self.error_message(), + RmtDataBaseErrors::default_help_message().italic() + ) + } +} + +impl Error for RmtDataBaseErrors {} diff --git a/src/main.rs b/src/main.rs index ded551f..6b54b0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,16 +3,17 @@ pub mod config; pub mod config_manager; pub mod data_manager; pub mod display_manager; -pub mod error_manager; +pub mod argument_errors; pub mod input_manager; pub mod structure_manager; pub mod trash_item; pub mod trash_manager; +pub mod database_errors; use arguments_manager::ArgumentsManager; use clap::Parser; use colored::Colorize; -use crate::error_manager::RmtArgumentErrors; +use crate::argument_errors::RmtArgumentErrors; fn main() { let is_test = false; diff --git a/src/trash_manager.rs b/src/trash_manager.rs index de7c0ae..592d22c 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -1,6 +1,6 @@ use crate::arguments_manager::ArgumentsManager; use crate::display_manager; -use crate::error_manager::RmtArgumentErrors; +use crate::argument_errors::RmtArgumentErrors; use crate::structure_manager::{self, get_element_name, get_element_path, get_home_directory_path}; use crate::{ config::Config, data_manager, structure_manager::get_trash_directory_path, From 6a35c6130c83478b0842361196ff37d759aea034 Mon Sep 17 00:00:00 2001 From: AmineZouitine Date: Thu, 13 Oct 2022 21:30:41 +0200 Subject: [PATCH 5/5] add error database --- src/data_manager.rs | 85 +++++++++++++++++++++++++----------------- src/database_errors.rs | 25 ++++++++----- src/main.rs | 4 +- src/trash_manager.rs | 2 +- 4 files changed, 70 insertions(+), 46 deletions(-) diff --git a/src/data_manager.rs b/src/data_manager.rs index 3d31f28..824df83 100644 --- a/src/data_manager.rs +++ b/src/data_manager.rs @@ -1,5 +1,7 @@ -use crate::structure_manager; +use std::process::exit; + use crate::trash_item::TrashItem; +use crate::{database_errors::RmtDataBaseErrors, structure_manager}; use rusqlite::{params, types::FromSql, Connection, Row}; // Create the database and the table to save information about deleted elements. @@ -7,10 +9,9 @@ pub fn setup_data_base(is_test: bool) -> Connection { let connection = structure_manager::create_data_base_file(is_test); let table_name = structure_manager::get_data_base_table_name(is_test); - connection - .execute( - &format!( - "CREATE TABLE IF NOT EXISTS {} ( + let stmt_result = connection.execute( + &format!( + "CREATE TABLE IF NOT EXISTS {} ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, hash NOT NULL UNIQUE, @@ -20,29 +21,41 @@ pub fn setup_data_base(is_test: bool) -> Connection { compression_size INTEGER, is_folder INTEGER NOT NULL )", - table_name - ), - [], - ) - .unwrap_or_else(|_| panic!("Unable to execute creation of {} table", table_name)); - - connection + table_name + ), + [], + ); + + match stmt_result { + Ok(_) => connection, + Err(_) => { + println!("{}", RmtDataBaseErrors::DataBaseCreation); + exit(1); + } + } } fn get(row: &Row, index: usize) -> T { - let element: T = row - .get(index) - .unwrap_or_else(|_| panic!("Get a {} not valid", index)); - element + match row.get(index) { + Ok(element) => element, + Err(_) => { + println!("{}", RmtDataBaseErrors::GetCellElement(index)); + exit(1); + } + } } // Find all elements on the table and convert them to TrashItems pub fn find_all_trash_items(connection: &Connection, is_test: bool) -> Vec { let table_name = structure_manager::get_data_base_table_name(is_test); - let mut stmt = connection - .prepare(&format!("SELECT * FROM {}", table_name)) - .expect("Cannot select every element in database"); + let mut stmt = match connection.prepare(&format!("SELECT * FROM {}", table_name)) { + Ok(stmt) => stmt, + Err(_) => { + println!("{}", RmtDataBaseErrors::SelectAllElements); + exit(1); + } + }; let mut trash_items = Vec::::new(); @@ -88,7 +101,7 @@ pub fn delete_trash_item_by_id(connection: &Connection, is_test: bool, id: i32) pub fn insert_trash_item(connection: &Connection, trash_item: &TrashItem, is_test: bool) { let table_name = structure_manager::get_data_base_table_name(is_test); - connection + let stmt_result = connection .execute( &format!("INSERT INTO {} (name, hash, path, date, real_size, compression_size, is_folder) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)", table_name), params![ @@ -100,25 +113,29 @@ pub fn insert_trash_item(connection: &Connection, trash_item: &TrashItem, is_tes trash_item.compression_size, trash_item.is_folder ], - ) - .unwrap_or_else(|_| panic!("Unable to do insert element request with this values : {:?}", - trash_item)); + ); + + match stmt_result { + Ok(_) => (), + Err(_) => println!("{}", RmtDataBaseErrors::InsertTrashItem), + }; } pub fn delete_trash_item(connection: &Connection, trash_item_id: i32, is_test: bool) { let table_name = structure_manager::get_data_base_table_name(is_test); - connection - .execute( - &format!("DELETE FROM {} WHERE id = (?1)", table_name), - params![trash_item_id], - ) - .unwrap_or_else(|_| { - panic!( - "Unable to do delete element request with this id : {}", - trash_item_id - ) - }); + let stmt_result = connection.execute( + &format!("DELETE FROM {} WHERE id = (?1)", table_name), + params![trash_item_id], + ); + + match stmt_result { + Ok(_) => (), + Err(_) => { + println!("{}", RmtDataBaseErrors::DeleteElementById(trash_item_id)); + exit(1); + } + } } pub fn delete_all_trash_item(connection: &Connection, is_test: bool) { diff --git a/src/database_errors.rs b/src/database_errors.rs index cff16c3..dd32992 100644 --- a/src/database_errors.rs +++ b/src/database_errors.rs @@ -3,27 +3,34 @@ use std::error::Error; use colored::Colorize; -use crate::trash_item::{TrashItem}; +use crate::trash_item::TrashItem; #[derive(Debug)] pub enum RmtDataBaseErrors { DataBaseCreation, SelectAllElements, - GetCellElement(u8), + GetCellElement(usize), DeleteElementById(i32), - InsertTrashItem(TrashItem), - DeleteAllElement - + InsertTrashItem, + DeleteAllElement, } impl RmtDataBaseErrors { fn error_message(&self) -> String { match self { RmtDataBaseErrors::DataBaseCreation => "Impossible to create the database.".to_string(), - RmtDataBaseErrors::SelectAllElements => "Impossible to select all the elements.".to_string(), - RmtDataBaseErrors::GetCellElement(index) => format!("Impossible to retrieve the cell with index {}.", index.to_string().red().bold()), - RmtDataBaseErrors::DeleteElementById(id) => format!("Impossible to delete the element at index {}.", id.to_string().red().bold()), - RmtDataBaseErrors::InsertTrashItem(trash_item) => format!("Impossible to insert the trashItem {}.", trash_item.to_string().red().bold()), + RmtDataBaseErrors::SelectAllElements => { + "Impossible to select all the elements.".to_string() + } + RmtDataBaseErrors::GetCellElement(index) => format!( + "Impossible to retrieve the cell with index {}.", + index.to_string().red().bold() + ), + RmtDataBaseErrors::DeleteElementById(id) => format!( + "Impossible to delete the element at index {}.", + id.to_string().red().bold() + ), + RmtDataBaseErrors::InsertTrashItem => format!("Impossible to insert the trashItem.",), RmtDataBaseErrors::DeleteAllElement => "Impossible to delete all elements.".to_string(), } } diff --git a/src/main.rs b/src/main.rs index 6b54b0a..35e57cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,14 @@ +pub mod argument_errors; pub mod arguments_manager; pub mod config; pub mod config_manager; pub mod data_manager; +pub mod database_errors; pub mod display_manager; -pub mod argument_errors; pub mod input_manager; pub mod structure_manager; pub mod trash_item; pub mod trash_manager; -pub mod database_errors; use arguments_manager::ArgumentsManager; use clap::Parser; use colored::Colorize; diff --git a/src/trash_manager.rs b/src/trash_manager.rs index 592d22c..c1c9702 100644 --- a/src/trash_manager.rs +++ b/src/trash_manager.rs @@ -1,6 +1,6 @@ +use crate::argument_errors::RmtArgumentErrors; use crate::arguments_manager::ArgumentsManager; use crate::display_manager; -use crate::argument_errors::RmtArgumentErrors; use crate::structure_manager::{self, get_element_name, get_element_path, get_home_directory_path}; use crate::{ config::Config, data_manager, structure_manager::get_trash_directory_path,