flexaudio_encode/error.rs
1//! Error and result types for flexaudio-encode.
2
3/// Errors that can occur during flexaudio-encode operations.
4///
5/// Marked `#[non_exhaustive]` so variants can be added later (external matches need `_ =>`).
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum EncodeError {
9 /// File I/O failed.
10 #[error("io error: {0}")]
11 Io(#[from] std::io::Error),
12 /// An unsupported parameter, such as channel count, sample rate, or chunk length.
13 #[error("unsupported: {0}")]
14 Unsupported(String),
15 /// An internal FLAC encoder error with a description.
16 #[error("encoder error: {0}")]
17 Encoder(String),
18}
19
20/// Result type used throughout flexaudio-encode.
21pub type Result<T> = std::result::Result<T, EncodeError>;
22
23impl EncodeError {
24 /// Shared typed binding projection with opt-in original diagnostics.
25 /// Safe Display never includes output paths or third-party encoder messages.
26 pub fn audio_error(&self) -> flexaudio_core::Error {
27 use flexaudio_core::{AddonErrorKind as Kind, Error};
28 let kind = match self {
29 Self::Io(_) => Kind::FlacIo,
30 Self::Unsupported(_) => Kind::FlacUnsupported,
31 Self::Encoder(_) => Kind::FlacEncoder,
32 };
33 Error::Addon {
34 kind,
35 message: self.to_string(),
36 }
37 }
38}