voicemeeter\interface\parameters/
errors.rs

1use crate::types::ZIndex;
2
3/// Parameter is out of range for current program
4#[derive(thiserror::Error, Debug, Clone)]
5#[error("out of range: {name}({index}) is not supported on `{program}`")]
6pub struct OutOfRangeError {
7    /// Name of the parameter `base` i.e "Strip" or "Bus"
8    pub name: String,
9    /// Index that was out of range
10    pub index: ZIndex,
11    /// Current program
12    pub program: super::VoicemeeterApplication,
13}
14
15/// Device is invalid for the current program and parameter
16#[derive(thiserror::Error, Debug, Clone)]
17#[error("invalid device: {device:?} is not supported on `{program}`")]
18#[non_exhaustive]
19pub struct DeviceError {
20    /// Current program
21    pub program: super::VoicemeeterApplication,
22    /// Device that was invalid
23    pub device: crate::types::Device,
24}
25
26/// Invalid strip/bus type for a specific parameter
27#[derive(thiserror::Error, Debug, Clone)]
28#[non_exhaustive]
29pub enum InvalidTypeError {
30    /// Expected Physical
31    #[error(
32        "{name}[{strip_index}] needs to be a physical {name} for access to parameter `{parameter}`"
33    )]
34    ExpectedPhysical {
35        /// Name of the parameter `base` i.e "Strip" or "Bus"
36        name: &'static str,
37        /// Index that was used
38        strip_index: ZIndex,
39        /// Parameter that expected a physical strip/bus
40        parameter: String,
41    },
42    /// Expected Virtual
43    #[error(
44        "{name}[{strip_index}] needs to be a virtual {name} for access to parameter `{parameter}`"
45    )]
46    ExpectedVirtual {
47        /// Name of the parameter `base` i.e "Strip" or "Bus"
48        name: &'static str,
49        /// Index that was used
50        strip_index: ZIndex,
51        /// Parameter that expected a physical strip/bus
52        parameter: String,
53    },
54    /// Expected Strip
55    #[error("expected a strip, got `{device}`")]
56    ExpectedStrip {
57        /// Device received
58        device: String,
59    },
60    /// Expected Bus
61    #[error("expected a bus, got `{device}`")]
62    ExpectedBus {
63        /// Device received
64        device: String,
65    },
66}
67
68/// Invalid Voicemeeter program
69#[derive(thiserror::Error, Debug, Clone)]
70#[error("{parameter} requires programs {expected:?} to be accessed, program is {found}")]
71pub struct InvalidVoicemeeterVersion {
72    /// Expected programs
73    pub expected: &'static [super::VoicemeeterApplication],
74    /// Found program
75    pub found: super::VoicemeeterApplication,
76    /// Parameter that expected a physical strip/bus
77    pub parameter: String,
78}
79
80/// Invalid Parameter
81#[derive(thiserror::Error, Debug, Clone)]
82pub enum ParameterError {
83    /// Version is not compatible with parameter
84    #[error(transparent)]
85    Version(#[from] InvalidVoicemeeterVersion),
86    /// Strip/bus is not compatible with parameter
87    #[error(transparent)]
88    Type(#[from] InvalidTypeError),
89    /// Parameter index is out of range
90    #[error(transparent)]
91    OutOfRange(#[from] OutOfRangeError),
92    /// Device is invalid for parameter
93    #[error(transparent)]
94    Device(#[from] DeviceError),
95}