honk_core/error.rs
1//! Error types for `honk-core`.
2//!
3//! A small `thiserror`-based enum to start from. Add variants as your tool
4//! grows; the CLI converts these into `anyhow::Error` automatically via the
5//! `?` operator.
6
7use thiserror::Error;
8
9/// Convenient result alias used throughout the core crate.
10pub type Result<T> = std::result::Result<T, Error>;
11
12/// Errors produced by the core crate.
13#[derive(Debug, Error)]
14pub enum Error {
15 /// An I/O operation failed (reading/writing config, etc.).
16 #[error("i/o error: {0}")]
17 Io(#[from] std::io::Error),
18
19 /// Failed to (de)serialize configuration.
20 #[error("config error: {0}")]
21 Config(String),
22
23 /// A honk parameter is out of range.
24 #[error("{0}")]
25 InvalidSpec(String),
26
27 /// Writing a WAV file failed.
28 #[error("could not write WAV: {0}")]
29 Wav(String),
30
31 /// The platform did not expose a config directory.
32 #[error("could not determine the configuration directory")]
33 NoConfigDir,
34}
35
36impl From<serde_norway::Error> for Error {
37 fn from(e: serde_norway::Error) -> Self {
38 Error::Config(e.to_string())
39 }
40}