use crate::{
errors::{APIError, CatBridgeError, NetworkError},
mion::firmware::MionFirmwareAPIError,
};
use miette::Diagnostic;
use thiserror::Error;
#[cfg(any(feature = "clients", feature = "servers"))]
use crate::{
errors::NetworkParseError,
mion::proto::{
cgis::MionCGIErrors,
control::MionControlProtocolError,
parameter::{MionParamProtocolError, MionParameterAPIError},
},
};
#[derive(Error, Diagnostic, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum MionAPIError {
#[error("You cannot set a default bridge that does not exist.")]
#[diagnostic(code(cat_dev::api::mion::default_device_must_exist))]
DefaultDeviceMustExist,
#[error("The device name cannot be empty, it must be at least one byte long.")]
#[diagnostic(code(cat_dev::api::mion::device_name_cannot_be_empty))]
DeviceNameCannotBeEmpty,
#[error("A device name has to be completely ASCII! But it wasn't ASCII!")]
#[diagnostic(code(cat_dev::api::mion::device_name_not_ascii))]
DeviceNameMustBeAscii,
#[error("A Device Name can only be 255 bytes long, but you specified one: {0} bytes long.")]
#[diagnostic(code(cat_dev::api::mion::device_name_too_long))]
DeviceNameTooLong(usize),
#[error(transparent)]
#[diagnostic(transparent)]
Firmware(#[from] MionFirmwareAPIError),
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
#[error(transparent)]
#[diagnostic(transparent)]
ParameterSpace(#[from] MionParameterAPIError),
}
impl From<MionFirmwareAPIError> for APIError {
fn from(value: MionFirmwareAPIError) -> Self {
Self::Mion(value.into())
}
}
impl From<MionFirmwareAPIError> for CatBridgeError {
fn from(value: MionFirmwareAPIError) -> Self {
Self::API(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionParameterAPIError> for APIError {
fn from(value: MionParameterAPIError) -> Self {
Self::Mion(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionParameterAPIError> for CatBridgeError {
fn from(value: MionParameterAPIError) -> Self {
Self::API(value.into())
}
}
#[derive(Error, Diagnostic, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum MionProtocolError {
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
#[error(transparent)]
#[diagnostic(transparent)]
CGI(#[from] MionCGIErrors),
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
#[error(transparent)]
#[diagnostic(transparent)]
Control(#[from] MionControlProtocolError),
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
#[error(transparent)]
#[diagnostic(transparent)]
Params(#[from] MionParamProtocolError),
}
impl From<MionProtocolError> for NetworkError {
fn from(value: MionProtocolError) -> Self {
Self::Parse(value.into())
}
}
impl From<MionProtocolError> for CatBridgeError {
fn from(value: MionProtocolError) -> Self {
Self::Network(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionCGIErrors> for NetworkParseError {
fn from(value: MionCGIErrors) -> Self {
Self::Mion(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionCGIErrors> for NetworkError {
fn from(value: MionCGIErrors) -> Self {
Self::Parse(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionCGIErrors> for CatBridgeError {
fn from(value: MionCGIErrors) -> Self {
Self::Network(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionParamProtocolError> for NetworkParseError {
fn from(value: MionParamProtocolError) -> Self {
Self::Mion(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionParamProtocolError> for NetworkError {
fn from(value: MionParamProtocolError) -> Self {
Self::Parse(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionParamProtocolError> for CatBridgeError {
fn from(value: MionParamProtocolError) -> Self {
Self::Network(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionControlProtocolError> for NetworkParseError {
fn from(value: MionControlProtocolError) -> Self {
Self::Mion(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionControlProtocolError> for NetworkError {
fn from(value: MionControlProtocolError) -> Self {
Self::Parse(value.into())
}
}
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
impl From<MionControlProtocolError> for CatBridgeError {
fn from(value: MionControlProtocolError) -> Self {
Self::Network(value.into())
}
}