gukhanmun/error.rs
1// Gukhanmun: umbrella library that wires the engine and adapters together.
2// Copyright (C) 2026 Hong Minhee
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! Umbrella error type that aggregates failures from the sub-crates that
18//! make up the gukhanmun pipeline.
19
20use thiserror::Error;
21
22/// Aggregated error type returned by the umbrella `gukhanmun` crate.
23///
24/// Each variant wraps a sub-crate's error and is gated on the same Cargo
25/// feature that activates the sub-crate. The variant for the always-present
26/// `gukhanmun-core` crate is unconditional.
27///
28/// `Error` is `#[non_exhaustive]` so that additional variants can be added in
29/// a minor release as new sub-crates or boundary failures are introduced.
30#[derive(Debug, Error)]
31#[non_exhaustive]
32pub enum Error {
33 /// An error emitted by `gukhanmun-core` (engine, dictionaries, IR).
34 #[error(transparent)]
35 Core(#[from] gukhanmun_core::Error),
36
37 /// An error emitted by `gukhanmun-html` (HTML reader / writer).
38 #[cfg(feature = "html")]
39 #[error(transparent)]
40 Html(#[from] gukhanmun_html::HtmlError),
41
42 /// An error emitted by `gukhanmun-markdown` (Markdown reader / writer).
43 #[cfg(feature = "markdown")]
44 #[error(transparent)]
45 Markdown(#[from] gukhanmun_markdown::MarkdownError),
46
47 /// An error emitted by `gukhanmun-fst` (FST dictionary backend).
48 #[cfg(feature = "fst")]
49 #[error(transparent)]
50 Fst(#[from] gukhanmun_fst::Error),
51
52 /// An error emitted by `gukhanmun-cdb` (CDB dictionary backend).
53 #[cfg(feature = "cdb")]
54 #[error(transparent)]
55 Cdb(#[from] gukhanmun_cdb::Error),
56
57 /// An I/O error encountered while loading a dictionary or reading
58 /// boundary bytes.
59 #[error("I/O error: {0}")]
60 Io(#[from] std::io::Error),
61
62 /// A configuration error reported by the umbrella facade itself, such
63 /// as requesting the bundled `stdict` without the `stdict` feature
64 /// enabled, or supplying an unsupported dictionary format.
65 #[error("configuration error: {0}")]
66 Config(String),
67}
68
69/// Convenience [`std::result::Result`] alias that defaults the error
70/// parameter to the umbrella [`enum@Error`].
71pub type Result<T, E = Error> = std::result::Result<T, E>;