cat_dev/fsemul/pcfs/
errors.rs1use miette::Diagnostic;
4use thiserror::Error;
5
6#[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
7#[cfg(any(feature = "clients", feature = "servers"))]
8use crate::fsemul::pcfs::sata::proto::SataQueryResponse;
9
10#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
12pub enum PcfsApiError {
13 #[error("Mode string is expected to match '(r|w|a)b?+?', but did not! invalid mode: {0}")]
14 #[diagnostic(code(cat_dev::api::fsmeul::pcfs::bad_mode_string))]
15 BadModeString(String),
16 #[error(
19 "This packet body is too large to ever fit in a PCFS Sata Packet, is: 0x{0:02X?} bytes long, max is 0xFFFFFFFF!"
20 )]
21 #[diagnostic(code(cat_dev::api::fsemul::pcfs::packet_too_large_for_sata))]
22 PacketTooLargeForSata(usize),
23 #[error("The requested path: [{0}] is too long, paths must be no more than 511 bytes.")]
24 #[diagnostic(code(cat_dev::api::fsemul::pcfs::path_too_long))]
25 PathTooLong(String),
26 #[error("The requested path: [{0}] was not inside of a mapped directory, cannot serve.")]
28 #[diagnostic(code(cat_dev::api::fsemul::pcfs::path_not_mapped))]
29 PathNotMapped(String),
30 #[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
31 #[cfg(feature = "servers")]
32 #[error(
33 "The server was not configured correctly (programmer error), please report that extension: {0} did not load properly!"
34 )]
35 #[diagnostic(code(cat_dev::api::fsemul::pcfs::missing_server_extension))]
36 MissingCriticalExtension(String),
37}
38
39#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
41#[non_exhaustive]
42pub enum SataProtocolError {
43 #[error("Mode string is expected to match '(r|w|a)b?+?', but did not! invalid mode: {0}")]
44 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::bad_mode_string))]
45 BadModeString(String),
46 #[error(
48 "Packet header for PCFS should end with 8 bytes of padding (all 0x0), but was: [{0:02X?}]!"
49 )]
50 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_bad_padding))]
51 HeaderBadPadding([u8; 8]),
52 #[error(
56 "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."
57 )]
58 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::header_non_host_set_host_fields))]
59 NonHostSetHostOnlyHeaderFields(u32, u32),
60 #[error("Unknown type of packet for PCFS Sata: {0:02X}!")]
62 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_type))]
63 UnknownPacketType(u32),
64 #[error("Unknown query type for GetInfo operation: {0}")]
66 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_get_info_query_type))]
67 UnknownGetInfoQueryType(u32),
68 #[error("Unknown file location to move too: {0}")]
69 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::unknown_file_location))]
70 UnknownFileLocation(u32),
71 #[cfg_attr(docsrs, doc(cfg(any(feature = "clients", feature = "servers"))))]
72 #[cfg(any(feature = "clients", feature = "servers"))]
73 #[error("Sata query response returned the wrong type of response: {0:?}")]
74 #[diagnostic(code(cat_dev::net::parse::pcfs::sata::wrong_query_response_type))]
75 WrongSataQueryResponse(SataQueryResponse),
76}