cat_dev/fsemul/sdio/
errors.rs1use bytes::Bytes;
4use miette::Diagnostic;
5use thiserror::Error;
6use tokio::sync::mpsc::error::SendError as BlockingSendError;
7
8#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum SdioApiError {
12 #[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 #[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#[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#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
53pub enum SdioProtocolError {
54 #[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 #[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 #[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 #[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 #[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}