-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a26bac2
commit f522750
Showing
4 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters