use super::*;
use crate::*;
use snafu::prelude::*;
use std::fmt::{Display, Formatter};
#[allow(missing_docs)]
#[derive(Debug, Snafu, Clone)]
#[snafu(visibility(pub(crate)))]
#[cfg_attr(
feature = "python-bindings",
gen_stub_pyclass_complex_enum,
pyclass(from_py_object)
)]
pub enum StreamMgrError {
#[snafu(display("API '{}' is not available.", apiname))]
ApiNotAvailable { apiname: String },
#[snafu(display("API specific error: {}", msg))]
APISpecificError { msg: String },
#[snafu(display("Backend specific error: {}", msg))]
BackendSpecificError { msg: String },
#[snafu(display("Unable to start a default stream: CPAL API is not available"))]
CPALNotAvailable {},
#[snafu(display("Data type not supported: {dtype}"))]
DataTypeNotSupported { dtype: String },
#[snafu(display("DAQ Configuration error: {}", msg))]
DAQConfigError { msg: String },
#[snafu(display("DAQ Configuration validation error: {}", source))]
DAQConfigValidationError { source: ValidationError },
#[snafu(display("Device {} not available", device_name))]
DeviceNotAvailableError { device_name: String },
DeviceScanAlreadyInProgress {},
#[snafu(display("Cannot perform operation: an input stream is (already) running"))]
InputStreamAlreadyRunning {},
#[snafu(display("Cannot perform operation: an input stream is not running"))]
InputStreamNotRunning {},
#[snafu(display("Cannot perform operation: an output stream is (already) running"))]
OutputStreamAlreadyRunning {},
#[snafu(display("Cannot perform operation: an output stream is not running"))]
OutputStreamNotRunning {},
#[snafu(display("Signal generator error: {}", source))]
SiggenError { source: crate::siggen::SiggenError },
#[snafu(display("Stream error: {}", source))]
StreamError { source: StreamError },
#[snafu(display(
"Buffer size not supported by the device: min={}, max={}, requested={}",
min,
max,
requested
))]
BufferSizeNotSupported { min: u32, max: u32, requested: u32 },
NoDefaultDeviceFound {},
}
cfg_select! {
any(feature="python-bindings") => {
use pyo3::exceptions::PyException;
#[gen_stub_pyclass]
#[pyclass(extends = PyException, str, from_py_object)] #[derive(Debug, Clone)]
pub struct PyStreamMgrError {
#[pyo3(get)]
pub inner: StreamMgrError,
}
impl Display for PyStreamMgrError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.inner)
}
}
#[gen_stub_pymethods]
#[pymethods]
impl PyStreamMgrError {
#[new]
fn new(inner: StreamMgrError) -> Self {
PyStreamMgrError { inner }
}
}
impl From<StreamMgrError> for PyErr {
fn from(value: StreamMgrError) -> Self {
PyErr::new::<PyStreamMgrError, _>(value)
}
}
}
_ => {}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_stream_mgr_error() {
let err = StreamMgrError::ApiNotAvailable {
apiname: "testapi".to_string(),
};
assert_eq!(err.to_string(), "API 'testapi' is not available.");
assert_eq!(format!("{}", err), "API 'testapi' is not available.");
}
}