use miette::Diagnostic;
use thiserror::Error;
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
use crate::fsemul::pcfs::sata::proto::SataQueryResponse;
#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
pub enum PcfsApiError {
#[error("Mode string is expected to match '(r|w|a)b?+?', but did not! invalid mode: {0}")]
#[diagnostic(code(cat_dev::api::fsmeul::pcfs::bad_mode_string))]
BadModeString(String),
#[error(
"This packet body is too large to ever fit in a PCFS Sata Packet, is: 0x{0:02X?} bytes long, max is 0xFFFFFFFF!"
)]
#[diagnostic(code(cat_dev::api::fsemul::pcfs::packet_too_large_for_sata))]
PacketTooLargeForSata(usize),
#[error("The requested path: [{0}] is too long, paths must be no more than 511 bytes.")]
#[diagnostic(code(cat_dev::api::fsemul::pcfs::path_too_long))]
PathTooLong(String),
#[error("The requested path: [{0}] was not inside of a mapped directory, cannot serve.")]
#[diagnostic(code(cat_dev::api::fsemul::pcfs::path_not_mapped))]
PathNotMapped(String),
#[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
#[cfg(feature = "servers")]
#[error(
"The server was not configured correctly (programmer error), please report that extension: {0} did not load properly!"
)]
#[diagnostic(code(cat_dev::api::fsemul::pcfs::missing_server_extension))]
MissingCriticalExtension(String),
}
#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum SataProtocolError {
#[error("Mode string is expected to match '(r|w|a)b?+?', but did not! invalid mode: {0}")]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::bad_mode_string))]
BadModeString(String),
#[error(
"Packet header for PCFS should end with 8 bytes of padding (all 0x0), but was: [{0:02X?}]!"
)]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_bad_padding))]
HeaderBadPadding([u8; 8]),
#[error(
"Packet header has fields that only the host should ever populate, but they were populated by the non-host: (timestamp: {0:02X}) / (pid: {1:02X}). This is a malformed packet from this device."
)]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_non_host_set_host_fields))]
NonHostSetHostOnlyHeaderFields(u32, u32),
#[error("Unknown type of packet for PCFS Sata: {0:02X}!")]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_type))]
UnknownPacketType(u32),
#[error("Unknown query type for GetInfo operation: {0}")]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_get_info_query_type))]
UnknownGetInfoQueryType(u32),
#[error("Unknown file location to move too: {0}")]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_file_location))]
UnknownFileLocation(u32),
#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
#[cfg(any(feature = "clients", feature = "servers"))]
#[error("Sata query response returned the wrong type of response: {0:?}")]
#[diagnostic(code(cat_dev::net::parse::pcfs::sata::wrong_query_response_type))]
WrongSataQueryResponse(SataQueryResponse),
}