weirdnet_audio_plugin/
error.rs1use weirdnet_media::waveform::WaveformError;
2
3#[derive(Debug, Clone, PartialEq)]
5pub enum PluginError {
6 InvalidParam { name: String, reason: String },
8 UnsupportedFormat,
10 TooLong { max_frames: usize },
12 Internal(String),
14}
15
16impl PluginError {
17 pub(crate) fn invalid(name: &str, reason: impl Into<String>) -> Self {
18 PluginError::InvalidParam { name: name.to_string(), reason: reason.into() }
19 }
20}
21
22impl std::fmt::Display for PluginError {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 PluginError::InvalidParam { name, reason } => write!(f, "parameter {name}: {reason}"),
26 PluginError::UnsupportedFormat => write!(f, "the plugin does not support this waveform's format"),
27 PluginError::TooLong { max_frames } => write!(f, "the result would be longer than {max_frames} frames"),
28 PluginError::Internal(why) => write!(f, "{why}"),
29 }
30 }
31}
32
33impl std::error::Error for PluginError {}
34
35impl From<WaveformError> for PluginError {
36 fn from(e: WaveformError) -> Self {
37 match e {
38 WaveformError::UnsupportedChannels { .. } => PluginError::UnsupportedFormat,
39 WaveformError::TooLong { max_frames } => PluginError::TooLong { max_frames },
40 WaveformError::OutOfRange { what, .. } => PluginError::invalid(what, e.to_string()),
41 WaveformError::NotFinite(what) => PluginError::invalid(what, e.to_string()),
42 other => PluginError::Internal(other.to_string()),
43 }
44 }
45}