mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-30 13: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)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Overwrite(String),
|
Overwrite(String),
|
||||||
Unexpected,
|
Unexpected,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Display for Error {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Overwrite(key) => {
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Database(sqlite::Error),
|
Database(sqlite::Error),
|
||||||
Gemini(super::gemini::Error),
|
Gemini(super::gemini::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Display for Error {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Database(reason) => {
|
Self::Database(reason) => {
|
||||||
format!("Database error: {}", reason)
|
write!(f, "Database error: {reason}")
|
||||||
}
|
}
|
||||||
Self::Gemini(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)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Database(sqlite::Error),
|
Database(sqlite::Error),
|
||||||
Memory(super::memory::Error),
|
Memory(super::memory::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Display for Error {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Database(reason) => format!("Database error: {}", reason),
|
Self::Database(reason) => write!(f, "Database error: {reason}"),
|
||||||
Self::Memory(reason) => format!("Memory error: {}", reason.to_string()),
|
Self::Memory(reason) => write!(f, "Memory error: {reason}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::{Display, Formatter, Result};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Clear,
|
Clear,
|
||||||
@ -5,14 +7,14 @@ pub enum Error {
|
|||||||
Unexpected,
|
Unexpected,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Display for Error {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Clear => "Could not cleanup memory index".to_string(),
|
Self::Clear => write!(f, "Could not cleanup memory index"),
|
||||||
Self::Overwrite(key) => {
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Auth(super::auth::Error),
|
Auth(super::auth::Error),
|
||||||
@ -6,17 +8,17 @@ pub enum Error {
|
|||||||
Memory(super::memory::Error),
|
Memory(super::memory::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Display for Error {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
match self {
|
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) => {
|
Self::Certificate(reason) => {
|
||||||
format!("Could not create certificate: {}", reason)
|
write!(f, "Could not create certificate: {reason}")
|
||||||
}
|
}
|
||||||
Self::Database(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