use std::io;
use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] io::Error),
#[error("Dictionary not found at: {0}")]
DictionaryNotFound(PathBuf),
#[error("Invalid dictionary format: {0}")]
InvalidDictionaryFormat(String),
#[error("Dictionary file corrupted: {0}")]
CorruptedDictionary(String),
#[error("Memory mapping error: {0}")]
MmapError(String),
#[error("Trie lookup error: {0}")]
TrieLookupError(String),
#[error("Connection matrix error: {0}")]
MatrixError(String),
#[error("Character definition error: {0}")]
CharDefError(String),
#[error("Unknown word error: {0}")]
UnknownWordError(String),
#[error("Lattice construction error: {0}")]
LatticeError(String),
#[error("Viterbi algorithm error: {0}")]
ViterbiError(String),
#[error("Encoding error: {0}")]
EncodingError(String),
#[error("Default dictionary not found. Run 'mecrab init' to download and install IPADIC.")]
DefaultDictionaryNotFound,
#[error("Feature parsing error: {0}")]
FeatureParseError(String),
#[error("Format error: {0}")]
FormatError(String),
#[error("Vector store error: {0}")]
VectorError(String),
}
impl From<std::fmt::Error> for Error {
fn from(e: std::fmt::Error) -> Self {
Error::FormatError(e.to_string())
}
}
#[cfg(feature = "serde")]
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::FormatError(e.to_string())
}
}