Skip to main content

flexaudio_core/
addon_error.rs

1//! Stable typed addon causes shared by all binding projections.
2use crate::ErrorKind;
3
4/// Addon failure identity, independent of native or model diagnostic messages.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6#[non_exhaustive]
7pub enum AddonErrorKind {
8    /// VAD model loading failed; recreate the VAD session and retry.
9    VadModelLoad,
10    /// VAD inference failed; reset the VAD session and retry.
11    VadInference,
12    /// VAD configuration is invalid; correct the settings and retry.
13    VadInvalidConfig,
14    /// VAD input format is invalid; use a sample rate within 8000..=192000 Hz and nonzero channels.
15    VadInvalidFormat,
16    /// VAD resampling failed; reset the VAD session and retry.
17    VadResample,
18    /// VAD reset failed; recreate the VAD session and retry.
19    VadReset,
20    /// FLAC output I/O failed; check output access and available space, then retry.
21    FlacIo,
22    /// FLAC input is unsupported; correct the format and writer state, then retry.
23    FlacUnsupported,
24    /// FLAC encoding failed; recreate the writer and retry.
25    FlacEncoder,
26}
27impl AddonErrorKind {
28    /// Root core classification.
29    pub fn error_kind(self) -> ErrorKind {
30        match self {
31            Self::VadModelLoad => ErrorKind::Backend,
32            Self::VadInference => ErrorKind::Backend,
33            Self::VadInvalidConfig => ErrorKind::InvalidArg,
34            Self::VadInvalidFormat => ErrorKind::InvalidArg,
35            Self::VadResample => ErrorKind::Backend,
36            Self::VadReset => ErrorKind::Backend,
37            Self::FlacIo => ErrorKind::Backend,
38            Self::FlacUnsupported => ErrorKind::InvalidArg,
39            Self::FlacEncoder => ErrorKind::Backend,
40        }
41    }
42    /// Stable binding spelling.
43    pub fn as_str(self) -> &'static str {
44        match self {
45            Self::VadModelLoad => "vadModelLoad",
46            Self::VadInference => "vadInference",
47            Self::VadInvalidConfig => "vadInvalidConfig",
48            Self::VadInvalidFormat => "vadInvalidFormat",
49            Self::VadResample => "vadResample",
50            Self::VadReset => "vadReset",
51            Self::FlacIo => "flacIo",
52            Self::FlacUnsupported => "flacUnsupported",
53            Self::FlacEncoder => "flacEncoder",
54        }
55    }
56    /// Safe library-owned explanation and recovery guidance.
57    pub fn explanation(self) -> &'static str {
58        match self {
59            Self::VadModelLoad => "VAD model loading failed; recreate the VAD session and retry.",
60            Self::VadInference => "VAD inference failed; reset the VAD session and retry.",
61            Self::VadInvalidConfig => {
62                "VAD configuration is invalid; correct the settings and retry."
63            }
64            Self::VadInvalidFormat => {
65                "VAD input format is invalid; use a sample rate within 8000..=192000 Hz and nonzero channels."
66            }
67            Self::VadResample => "VAD resampling failed; reset the VAD session and retry.",
68            Self::VadReset => "VAD reset failed; recreate the VAD session and retry.",
69            Self::FlacIo => {
70                "FLAC output I/O failed; check output access and available space, then retry."
71            }
72            Self::FlacUnsupported => {
73                "FLAC input is unsupported; correct the format and writer state, then retry."
74            }
75            Self::FlacEncoder => "FLAC encoding failed; recreate the writer and retry.",
76        }
77    }
78}