meco_core/error.rs
1//! Error type. Folds the Java `State` / `TranslateState` / `DelehiState` runtime codes into one
2//! Rust enum.
3//!
4//! Note (design decision #3): a content-level *unmappable code point* is **not** an error here —
5//! it is passed through unchanged. So [`MecoError::NotFoundInMapper`] is reserved for internal/
6//! diagnostic use. The default build's public `translate` returns `Err` only for structural problems
7//! (unsupported encoding, unsupported series, unknown enum string) and for UTN #57 conversion
8//! failures reported by the in-process `zvvnmod-utn57` backend.
9
10use crate::code_type::CodeType;
11use std::fmt;
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum MecoError {
15 /// No translate rule registered for this code (defensive; should be unreachable for supported types).
16 MissTranslateRule(CodeType),
17 /// Internal stack underflow during fragment processing.
18 NothingToPop,
19 /// A key was not found in a mapper table (internal/diagnostic; content path passes through instead).
20 NotFoundInMapper(String),
21 /// A code's series was neither Letter nor Shape (defensive; unreachable given the enum).
22 NotSupportedCodeSeries(CodeType),
23 /// A string could not be parsed into a [`CodeType`].
24 UnsupportedEnumType(String),
25 /// Conversion involving this code is not supported in the active build.
26 Unsupported(CodeType),
27 /// An in-process UTN #57 conversion (`zvvnmod-utn57` + `mongol-norm`), either direction, failed.
28 Utn57(String),
29}
30
31impl fmt::Display for MecoError {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 MecoError::MissTranslateRule(ct) => write!(f, "missing translate rule for {ct:?}"),
35 MecoError::NothingToPop => write!(f, "nothing to pop"),
36 MecoError::NotFoundInMapper(k) => write!(f, "key not found in mapper: {k:?}"),
37 MecoError::NotSupportedCodeSeries(ct) => write!(f, "unsupported code series for {ct:?}"),
38 MecoError::UnsupportedEnumType(s) => write!(f, "unsupported encoding name: {s:?}"),
39 MecoError::Unsupported(ct) => write!(f, "conversion not supported for {ct:?}"),
40 MecoError::Utn57(reason) => write!(f, "UTN #57 conversion failed: {reason}"),
41 }
42 }
43}
44
45impl std::error::Error for MecoError {}