Skip to main content

word2vec/
error.rs

1//! Unified error type for the word2vec crate.
2
3use thiserror::Error;
4
5/// All errors that can occur during vocabulary building, training, or inference.
6#[derive(Debug, Error)]
7pub enum Word2VecError {
8    #[error("Vocabulary is empty — provide a non-empty corpus")]
9    EmptyVocabulary,
10
11    #[error("Word not found in vocabulary: `{0}`")]
12    UnknownWord(String),
13
14    #[error("Embedding dimension must be > 0, got {0}")]
15    InvalidDimension(usize),
16
17    #[error("Window size must be > 0, got {0}")]
18    InvalidWindowSize(usize),
19
20    #[error("Negative samples must be > 0, got {0}")]
21    InvalidNegativeSamples(usize),
22
23    #[error("I/O error: {0}")]
24    Io(#[from] std::io::Error),
25
26    #[error("Serialization error: {0}")]
27    Serialization(#[from] serde_json::Error),
28
29    #[error("Plot error: {0}")]
30    Plot(String),
31
32    #[error("Corpus too small: need at least 2 unique tokens, got {0}")]
33    CorpusTooSmall(usize),
34}
35
36pub type Result<T> = std::result::Result<T, Word2VecError>;