1use crate::{
4 errors::{APIError, CatBridgeError, NetworkError, NetworkParseError},
5 fsemul::{
6 pcfs::errors::{PcfsApiError, SataProtocolError},
7 sdio::errors::{SdioApiError, SdioNetworkError, SdioProtocolError},
8 },
9};
10use bytes::Bytes;
11use miette::Diagnostic;
12use std::path::PathBuf;
13use thiserror::Error;
14
15#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
17pub enum FSEmulAPIError {
18 #[error("File descriptors have already been opened, we cannot change our strategy now!")]
19 #[diagnostic(code(cat_dev::api::fsemul::cannot_swap_fd_strategy))]
20 CannotSwapFdStrategy,
21 #[error("DLF Address is too large ({0:016X}) to be inserted ({1:016X})")]
23 #[diagnostic(code(cat_dev::api::fsemul::dlf_address_too_large))]
24 DlfAddressTooLarge(u128, u128),
25 #[error("DLF Paths _MUST_ be able tto be encoded as UTF-8, this file path was not: {0:02X?}")]
26 #[diagnostic(code(cat_dev::api::fsemul::dlf_path_forced_utf8))]
27 DlfPathMustBeUtf8(Bytes),
28 #[error("DLF files must have an ending address that appears _last_, and is an empty string.")]
31 #[diagnostic(code(cat_dev::api::fsemul::dlf_must_have_ending))]
32 DlfMustHaveEnding,
33 #[error(
34 "You tried to place a disk item past the current ending, please update the ending, before updating the new item."
35 )]
36 #[diagnostic(code(cat_dev::api::fsemul::dlf_update_ending_first))]
37 DlfUpsertEndingFirst,
38 #[error("Failed to interact with path, file must be open first: {0:?}")]
39 #[diagnostic(code(cat_dev::api::fsemul::path_not_open))]
40 PathNotOpen(PathBuf),
41 #[error(transparent)]
42 #[diagnostic(transparent)]
43 Pcfs(#[from] PcfsApiError),
44 #[error(transparent)]
45 #[diagnostic(transparent)]
46 Sdio(#[from] SdioApiError),
47}
48
49impl From<FSEmulAPIError> for CatBridgeError {
50 fn from(value: FSEmulAPIError) -> Self {
51 Self::API(value.into())
52 }
53}
54
55impl From<PcfsApiError> for APIError {
56 fn from(value: PcfsApiError) -> Self {
57 Self::FSEmul(value.into())
58 }
59}
60impl From<PcfsApiError> for CatBridgeError {
61 fn from(value: PcfsApiError) -> Self {
62 Self::API(value.into())
63 }
64}
65
66impl From<SdioApiError> for APIError {
67 fn from(value: SdioApiError) -> Self {
68 Self::FSEmul(value.into())
69 }
70}
71impl From<SdioApiError> for CatBridgeError {
72 fn from(value: SdioApiError) -> Self {
73 Self::API(value.into())
74 }
75}
76
77#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
79pub enum FSEmulFSError {
80 #[error(
82 "We can't find the path to store fsemul configuration, please use explicit paths instead."
83 )]
84 #[diagnostic(code(cat_dev::fs::fsemul::cant_find_path))]
85 CantFindPath,
86 #[error("We can't find the root Cafe SDK folder, please use explicit paths instead.")]
88 #[diagnostic(code(cat_dev::fs::fsemul::cant_find_cafe_sdk_path))]
89 CantFindCafeSdkPath,
90 #[error("The Cafe SDK Path does not have the appropriate MLC path directories.")]
92 #[diagnostic(code(cat_dev::fs::fsemul::corrupt_cafe_sdk_path))]
93 CafeSdkPathCorrupt,
94 #[error(
96 "While parsing a disk layout file we ran into a line which is not in the format of: `<hex address>,\"<path>\"`: {0}"
97 )]
98 #[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_line))]
99 DlfCorruptLine(String),
100 #[error("DLF files must have a blank final line, but was: {0}")]
102 #[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_final_line))]
103 DlfCorruptFinalLine(String),
104 #[error(
106 "While parsing a disk layout file, the first line should be a version string (e.g. `v1.00`), which this was not: {0}"
107 )]
108 #[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_version_line))]
109 DlfCorruptVersionLine(String),
110}
111impl From<FSEmulFSError> for CatBridgeError {
112 fn from(value: FSEmulFSError) -> Self {
113 Self::FS(value.into())
114 }
115}
116
117#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
119pub enum FSEmulNetworkError {
120 #[error(transparent)]
121 #[diagnostic(transparent)]
122 Sdio(#[from] SdioNetworkError),
123}
124
125impl From<FSEmulNetworkError> for CatBridgeError {
126 fn from(value: FSEmulNetworkError) -> Self {
127 Self::Network(value.into())
128 }
129}
130
131impl From<SdioNetworkError> for NetworkError {
132 fn from(value: SdioNetworkError) -> Self {
133 Self::FSEmul(value.into())
134 }
135}
136impl From<SdioNetworkError> for CatBridgeError {
137 fn from(value: SdioNetworkError) -> Self {
138 Self::Network(value.into())
139 }
140}
141
142#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
144pub enum FSEmulProtocolError {
145 #[error(transparent)]
146 #[diagnostic(transparent)]
147 PcfsSata(#[from] SataProtocolError),
148 #[error(transparent)]
149 #[diagnostic(transparent)]
150 Sdio(#[from] SdioProtocolError),
151}
152
153impl From<FSEmulProtocolError> for NetworkError {
154 fn from(value: FSEmulProtocolError) -> Self {
155 Self::Parse(value.into())
156 }
157}
158impl From<FSEmulProtocolError> for CatBridgeError {
159 fn from(value: FSEmulProtocolError) -> Self {
160 Self::Network(value.into())
161 }
162}
163
164impl From<SataProtocolError> for NetworkParseError {
165 fn from(value: SataProtocolError) -> Self {
166 Self::FSEmul(value.into())
167 }
168}
169impl From<SataProtocolError> for NetworkError {
170 fn from(value: SataProtocolError) -> Self {
171 Self::Parse(value.into())
172 }
173}
174impl From<SataProtocolError> for CatBridgeError {
175 fn from(value: SataProtocolError) -> Self {
176 Self::Network(value.into())
177 }
178}
179
180impl From<SdioProtocolError> for NetworkParseError {
181 fn from(value: SdioProtocolError) -> Self {
182 Self::FSEmul(value.into())
183 }
184}
185impl From<SdioProtocolError> for NetworkError {
186 fn from(value: SdioProtocolError) -> Self {
187 Self::Parse(value.into())
188 }
189}
190impl From<SdioProtocolError> for CatBridgeError {
191 fn from(value: SdioProtocolError) -> Self {
192 Self::Network(value.into())
193 }
194}