cat_dev/fsemul/sdio/
errors.rs

1//! Errors related to SDIO protocols.
2
3use bytes::Bytes;
4use miette::Diagnostic;
5use thiserror::Error;
6use tokio::sync::mpsc::error::SendError as BlockingSendError;
7
8/// An API Error for interacting with the SDIO client.
9#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum SdioApiError {
12	/// Invalid LBA has been supplied, you might want to set the raw LBA.
13	#[error("The LBA provided was invalid, must be divisble by 512 bytes: {0}")]
14	#[diagnostic(code(cat_dev::api::fsemul::sdio::invalid_lba))]
15	InvalidLBA(u32),
16	/// An invalid channel name has been supplied.
17	#[error("The channel provided was invalid, (first byte: {0:02x}, should be <0xC), (full: {1})")]
18	#[diagnostic(code(cat_dev::api::fsemul::sdio::invalid_channel))]
19	InvalidChannel(u8, u32),
20	#[error("The telnet message provided was too long, (max 499 bytes), was: [{0:?}]")]
21	#[diagnostic(code(cat_dev::api::fsemul::sdio::telnet_message_too_long))]
22	TelnetMessageToLong(Bytes),
23}
24
25/// Error dealing with the network side of handling the SDIO protocol.
26#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
27pub enum SdioNetworkError {
28	#[error("Failed to request a read of: {0:?} bytes from the data stream.")]
29	#[diagnostic(code(cat_dev::net::fsemul::sdio::data_stream::cannot_request_read))]
30	CannotRequestReadFromDataStream(#[from] BlockingSendError<usize>),
31	#[error("Cannot queue a write to the data stream for SDIO: {0:?}")]
32	#[diagnostic(code(cat_dev::net::fsemul::sdio::data_stream::cannot_queue_write))]
33	CannotQueueWriteToDataStream(#[from] BlockingSendError<Bytes>),
34	#[error(
35		"The SDIO data stream did not respond with any data, this must mean it was closed previously in error."
36	)]
37	#[diagnostic(code(cat_dev::net::fsemul::sdio::data_stream::did_not_respond))]
38	DataStreamDidNotRespond,
39	#[error(
40		"Packet coming in on stream: {0} did not get a data stream allocated, internal developer error?"
41	)]
42	#[diagnostic(code(cat_dev::net::fsemul::sdio::data_stream::missing))]
43	DataStreamMissing(u64),
44	#[error(
45		"Packet coming in on stream: {0} did not get a buffer allocated, internal developer error?"
46	)]
47	#[diagnostic(code(cat_dev::net::fsemul::sdio::printf::missing_buffer))]
48	PrintfMissingBuffer(u64),
49}
50
51/// Error serializing/deserializing the SDIO protocol.
52#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
53pub enum SdioProtocolError {
54	/// SDIO addresses are out of range.
55	#[error("The SDIO client requested address: {0:02X}, but max address was: {1:02X}")]
56	#[diagnostic(code(cat_dev::net::parse::fsemul::sdio::address_out_of_range))]
57	AddressOutOfRange(u128, u128),
58	/// The first part of a 'printf' message is a channel identifier which is
59	/// like a stream identifier (think differences between STDIN/STDOUT/STDERR).
60	///
61	/// Unfortunately the channel specified was invalid.
62	#[error(
63		"Got an invalid channel to read/write from for sdio/printf, (first byte: {0:02x} should be <0xC), (full channel: {1})"
64	)]
65	#[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::invalid_channel))]
66	PrintfInvalidChannel(u8, u32),
67	/// All SDIO Printf messages must be 512 bytes long, this one was not.
68	#[error("Packet headed for SDIO PRINTF/CONTROL was size {0}, but needs to be 512 bytes")]
69	#[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::invalid_sized_packet))]
70	PrintfInvalidSize(usize),
71	/// Unknown command/packet type came over the SDIO protocol.
72	#[error("Got an unexpected sdio/printf packet type: {0}, not sure how to handle.")]
73	#[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::unknown_packet_type))]
74	UnknownPrintfPacketType(u16),
75	/// A 'printf' message, has an inner message type, which we didn't recognize.
76	#[error(
77		"Got an unexpected message fragment from an sdio printf packet type: {0}, not sure how to handle."
78	)]
79	#[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::unknown_message_type))]
80	UnknownPrintfTelnetChannel(u16),
81}