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("SDIO network did not come ready with a HostFilesystem attached!")]
45 #[diagnostic(code(cat_dev::net::fsemul::sdio::missing_filesystem))]
46 MissingFilesystem,
47 #[error(
48 "Packet coming in on stream: {0} did not get a buffer allocated, internal developer error?"
49 )]
50 #[diagnostic(code(cat_dev::net::fsemul::sdio::printf::missing_buffer))]
51 PrintfMissingBuffer(u64),
52}
53
54#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
56pub enum SdioProtocolError {
57 #[error("The SDIO client requested address: {0:02X}, but max address was: {1:02X}")]
59 #[diagnostic(code(cat_dev::net::parse::fsemul::sdio::address_out_of_range))]
60 AddressOutOfRange(u128, u128),
61 #[error(
66 "Got an invalid channel to read/write from for sdio/printf, (first byte: {0:02x} should be <0xC), (full channel: {1})"
67 )]
68 #[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::invalid_channel))]
69 PrintfInvalidChannel(u8, u32),
70 #[error("Packet headed for SDIO PRINTF/CONTROL was size {0}, but needs to be 512 bytes")]
72 #[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::invalid_sized_packet))]
73 PrintfInvalidSize(usize),
74 #[error("Got an unexpected sdio/printf packet type: {0}, not sure how to handle.")]
76 #[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::unknown_packet_type))]
77 UnknownPrintfPacketType(u16),
78 #[error(
80 "Got an unexpected message fragment from an sdio printf packet type: {0}, not sure how to handle."
81 )]
82 #[diagnostic(code(cat_dev::net::parse::fsemul::sdio::printf::unknown_message_type))]
83 UnknownPrintfTelnetChannel(u16),
84}