cat_dev/fsemul/pcfs/
errors.rs

1//! Errors related to various PCFS protocols.
2
3use 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/// Error's specific to calling a specific PCFS API.
11#[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	/// `PCFS` Sata protocol only supports [`u32::MAX`] packet sizes because they
17	/// store length of body as a [`u32`].
18	#[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	/// Requested path is not inside of a mapped directory.
27	#[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/// Error serializing/deserializing the PCFS Sata protocol.
40#[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	/// PCFS sata headers should always end with 8 NUL bytes for padding.
47	#[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	/// SATA packets have fields that only the host pc is supposed to set.
53	///
54	/// One of these fields was set by the client instead of the host pc.
55	#[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	/// Unknown type of packet received on PCFS Sata.
61	#[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	/// Unknown type of query for getting a files information.
65	#[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}