Skip to main content

jpreprocess_core/
error.rs

1use crate::{
2    accent_rule::AccentRuleParseError, ctype::CTypeParseError, pos::POSParseError,
3    pronunciation::PronunciationParseError,
4};
5
6#[derive(Debug, thiserror::Error)]
7pub enum JPreprocessError {
8    #[error("Io error: {0}")]
9    Io(#[from] std::io::Error),
10    #[error("Failed to fetch word from dictionary: {0}")]
11    DictionaryError(#[from] DictionaryError),
12    #[cfg(feature = "lindera")]
13    #[error("Lindera error: {0}")]
14    LinderaError(#[from] lindera::error::LinderaError),
15    #[error("Failed to parse pronunciation: {0}")]
16    PronunciationParseError(#[from] PronunciationParseError),
17    #[error("Failed to parse part of speech (POS): {0}")]
18    PartOfSpeechParseError(#[from] POSParseError),
19    #[error("Failed to parse conjugation type (CType): {0}")]
20    CTypeParseError(#[from] CTypeParseError),
21    #[error("Failed to parse conjugation form (CForm)")]
22    CFormParseError,
23    #[error("Failed to parse accent rule: {0}")]
24    AccentRuleParseError(#[from] AccentRuleParseError),
25    #[error("Provided mora size {0} is different from that of calculated from pronunciation {1}")]
26    MoraSizeMismatch(usize, usize),
27}
28
29#[derive(Debug, thiserror::Error)]
30pub enum DictionaryError {
31    #[error("Word with id {0} not found")]
32    IdNotFound(u32),
33    #[error("Failed to decode: {0}")]
34    FailDecode(#[from] bincode::error::DecodeError),
35    #[error("The word is flagged as UserDictionary, but Lindera UserDictionary is empty")]
36    UserDictionaryNotProvided,
37    #[error("The word is flagged as UserDictionary, but UserDictionary mode is not set")]
38    UserDictionaryModeNotSet,
39}