use std::{ string::FromUtf8Error, sync::{MutexGuard, PoisonError}, }; use rusqlite::Connection; use serde::Serialize; use thiserror::Error; use vibrato_rkyv::{Tokenizer, errors::VibratoError}; use zip::result::ZipError; #[derive(Debug, Error, Serialize)] #[serde(tag = "kind", content = "message")] pub enum CJDicError { #[error("Database error: {0}")] Database(String), #[error("Serialization error: {0}")] Serialization(String), #[error("Anyhow error: {0}")] AnyhowError(String), #[error("IO error: {0}")] IOError(String), #[error("File name not found")] FileNameNotFound, #[error("Zip error: {0}")] ZipError(String), #[error("Vibrato error: {0}")] VibratoError(String), #[error("FromUtf8Error: {0}")] FromUtf8Error(String), #[error("ConnectionMutexGuardError: {0}")] ConnectionMutexGuardError(String), #[error("TokenizerMutexGuardError: {0}")] TokenizerMutexGuardError(String), #[error("Not found")] NotFound, #[error("Error: {0}")] Error(String), } impl From for CJDicError { fn from(e: rusqlite::Error) -> Self { eprintln!("{e:#}"); CJDicError::Database(e.to_string()) } } impl From for CJDicError { fn from(e: serde_json::Error) -> Self { eprintln!("{e:#}"); CJDicError::Serialization(e.to_string()) } } impl From for CJDicError { fn from(e: anyhow::Error) -> Self { eprintln!("{e:#}"); CJDicError::AnyhowError(e.to_string()) } } impl From for CJDicError { fn from(e: std::io::Error) -> Self { eprintln!("{e:#}"); CJDicError::IOError(e.to_string()) } } impl From for CJDicError { fn from(e: ZipError) -> Self { eprintln!("{e:#}"); CJDicError::ZipError(e.to_string()) } } impl From for CJDicError { fn from(e: VibratoError) -> Self { eprintln!("{e:#}"); CJDicError::VibratoError(e.to_string()) } } impl From for CJDicError { fn from(e: FromUtf8Error) -> Self { eprintln!("{e:#}"); CJDicError::FromUtf8Error(e.to_string()) } } impl From>> for CJDicError { fn from(e: PoisonError>) -> Self { eprintln!("{e:#}"); CJDicError::ConnectionMutexGuardError(e.to_string()) } } impl From>> for CJDicError { fn from(e: PoisonError>) -> Self { eprintln!("{e:#}"); CJDicError::TokenizerMutexGuardError(e.to_string()) } }