Skip to main content

sophia/
error.rs

1// Copyright 2025 Aquila Labs of Alberta, Canada <matt@cicero.sh>
2// Licensed under the PolyForm Noncommercial License 1.0.0
3// Commercial use requires a separate license: https://cicero.sh/sophia/
4// License text: https://polyformproject.org/licenses/noncommercial/1.0.0/
5// Distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
6
7use std::fmt;
8
9#[derive(Debug)]
10pub enum Error {
11    Save(String),
12    Load(String),
13    POSPrediction(String),
14    Generic(String),
15}
16
17impl std::error::Error for Error {}
18
19impl fmt::Display for Error {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Error::Save(err) => write!(f, "Save error: {}", err),
23            Error::Load(err) => write!(f, "Load error: {}", err),
24            Error::POSPrediction(err) => write!(f, "POS tagger logistic regression error: {}", err),
25            Error::Generic(msg) => write!(f, "{}", msg),
26        }
27    }
28}
29
30impl From<std::io::Error> for Error {
31    fn from(err: std::io::Error) -> Self {
32        Error::Generic(err.to_string())
33    }
34}