mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 12:04:13 +00:00
implement Display trait for Error
This commit is contained in:
parent
a10825e91a
commit
a59a41f2a7
@ -1,16 +1,18 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Overwrite(String),
|
||||
Unexpected,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn to_string(&self) -> String {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Overwrite(key) => {
|
||||
format!("Overwrite attempt for existing record `{key}`")
|
||||
write!(f, "Overwrite attempt for existing record `{key}`")
|
||||
}
|
||||
Self::Unexpected => "Unexpected error".to_string(),
|
||||
Self::Unexpected => write!(f, "Unexpected error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Database(sqlite::Error),
|
||||
Gemini(super::gemini::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn to_string(&self) -> String {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Database(reason) => {
|
||||
format!("Database error: {}", reason)
|
||||
write!(f, "Database error: {reason}")
|
||||
}
|
||||
Self::Gemini(reason) => {
|
||||
format!("Could not init Gemini identity: {}", reason.to_string())
|
||||
write!(f, "Could not init Gemini identity: {reason}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Database(sqlite::Error),
|
||||
Memory(super::memory::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn to_string(&self) -> String {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Database(reason) => format!("Database error: {}", reason),
|
||||
Self::Memory(reason) => format!("Memory error: {}", reason.to_string()),
|
||||
Self::Database(reason) => write!(f, "Database error: {reason}"),
|
||||
Self::Memory(reason) => write!(f, "Memory error: {reason}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Clear,
|
||||
@ -5,14 +7,14 @@ pub enum Error {
|
||||
Unexpected,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn to_string(&self) -> String {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Clear => "Could not cleanup memory index".to_string(),
|
||||
Self::Clear => write!(f, "Could not cleanup memory index"),
|
||||
Self::Overwrite(key) => {
|
||||
format!("Overwrite attempt for existing record `{key}`")
|
||||
write!(f, "Overwrite attempt for existing record `{key}`")
|
||||
}
|
||||
Self::Unexpected => "Unexpected error".to_string(),
|
||||
Self::Unexpected => write!(f, "Unexpected error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Auth(super::auth::Error),
|
||||
@ -6,17 +8,17 @@ pub enum Error {
|
||||
Memory(super::memory::Error),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn to_string(&self) -> String {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Auth(reason) => format!("Could not create auth: {}", reason.to_string()),
|
||||
Self::Auth(reason) => write!(f, "Could not create auth: {reason}"),
|
||||
Self::Certificate(reason) => {
|
||||
format!("Could not create certificate: {}", reason)
|
||||
write!(f, "Could not create certificate: {reason}")
|
||||
}
|
||||
Self::Database(reason) => {
|
||||
format!("Database error: {}", reason)
|
||||
write!(f, "Database error: {reason}")
|
||||
}
|
||||
Self::Memory(reason) => format!("Memory error: {}", reason.to_string()),
|
||||
Self::Memory(reason) => write!(f, "Memory error: {reason}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user