dynomite/embed/error.rs
1//! Error types for the embedding API.
2//!
3//! Every public surface in [`crate::embed`] flows errors through
4//! [`EmbedError`]. The variants are intentionally coarse: the
5//! library code beneath the embed facade owns the precise typed
6//! error vocabulary; the embed surface is a thin user-facing
7//! shim.
8//!
9//! # Examples
10//!
11//! ```
12//! use dynomite::embed::EmbedError;
13//! let err = EmbedError::Build("listen address required".into());
14//! assert!(err.to_string().contains("listen"));
15//! ```
16
17use std::io;
18
19use thiserror::Error;
20
21use crate::conf::ConfError;
22
23/// Top-level error for every embedding-API call.
24///
25/// The variants partition the error space by the surface that
26/// produced the error: configuration validation
27/// ([`EmbedError::Build`]), runtime control
28/// ([`EmbedError::Shutdown`], [`EmbedError::Reload`]), traffic
29/// path ([`EmbedError::Inject`]), and the underlying I/O
30/// ([`EmbedError::Io`]).
31///
32/// # Examples
33///
34/// ```
35/// use dynomite::embed::EmbedError;
36/// let e: EmbedError = std::io::Error::other("boom").into();
37/// assert!(matches!(e, EmbedError::Io(_)));
38/// ```
39#[derive(Debug, Error)]
40#[non_exhaustive]
41pub enum EmbedError {
42 /// Configuration validation failed.
43 #[error("build error: {0}")]
44 Build(String),
45
46 /// Underlying YAML / pool validation rejected the config.
47 #[error("conf error: {0}")]
48 Conf(#[from] ConfError),
49
50 /// Graceful shutdown failed.
51 #[error("shutdown error: {0}")]
52 Shutdown(String),
53
54 /// Reload validation or apply failed.
55 #[error("reload error: {0}")]
56 Reload(String),
57
58 /// `inject_request` could not produce a response.
59 #[error("inject error: {0}")]
60 Inject(String),
61
62 /// I/O failure during a runtime operation (bind, accept, ...).
63 #[error("io error: {0}")]
64 Io(#[from] io::Error),
65
66 /// The runtime task was cancelled or the channel was closed.
67 #[error("server stopped")]
68 Stopped,
69}