use crate::kernel::lsm::compactor::CompactTask;
use crate::kernel::lsm::version::cleaner::CleanTag;
use std::io;
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;
use tokio::sync::oneshot::error::RecvError;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum KernelError {
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
RecvError(#[from] RecvError),
#[error("Failed to send compact task")]
SendCompactTaskError(#[from] SendError<CompactTask>),
#[error("Failed to send clean tag")]
SendCleanTagError(#[from] SendError<CleanTag>),
#[error(transparent)]
SerdeBinCode(#[from] Box<bincode::ErrorKind>),
#[error("Key not found")]
KeyNotFound,
#[error("Data is empty")]
DataEmpty,
#[error("Level Over")]
LevelOver,
#[error("Not the correct type of Cmd")]
NotMatchCmd,
#[error("CRC code does not match")]
CrcMisMatch,
#[cfg(feature = "sled")]
#[error(transparent)]
SledErr(#[from] sled::Error),
#[cfg(feature = "rocksdb")]
#[error(transparent)]
RocksdbErr(#[from] rocksdb::Error),
#[error("Cache size overflow")]
CacheSizeOverFlow,
#[error("Cache sharding and size overflow")]
CacheShardingNotAlign,
#[error("File not found")]
FileNotFound,
#[error("WAL log load error")]
WalLoad,
#[error("Unexpected command type")]
UnexpectedCommandType,
#[error("Process already exists")]
ProcessExists,
#[error("Channel is closed")]
ChannelClose,
#[error("{0}")]
NotSupport(&'static str),
#[error("The number of caches cannot be divisible by the number of shards")]
ShardingNotAlign,
#[error("Same write in different transactions")]
RepeatedWrite,
}
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum ConnectionError {
#[error(transparent)]
IO(#[from] io::Error),
#[error("disconnected")]
Disconnected,
#[error("write failed")]
WriteFailed,
#[error("wrong instruction")]
WrongInstruction,
#[error("encode error")]
EncodeErr,
#[error("decode error")]
DecodeErr,
#[error("server flush error")]
FlushError,
#[cfg(feature = "net")]
#[error("Failed to connect to server, {0}")]
TonicTransportErr(#[from] tonic::transport::Error),
#[cfg(feature = "net")]
#[error("Failed to call server, {0}")]
TonicFailureStatus(#[from] tonic::Status),
#[error("Failed to parse addr, {0}")]
AddrParseError(#[from] std::net::AddrParseError),
#[error(transparent)]
KernelError(#[from] KernelError),
}