cat_dev/fsemul/
errors.rs

1//! Errors for `PCFS`, and `FSEmul`.
2
3use crate::{
4	errors::{APIError, CatBridgeError, NetworkError, NetworkParseError},
5	fsemul::{
6		pcfs::errors::{PCFSApiError, SataProtocolError},
7		sdio::errors::SDIOProtocolError,
8	},
9};
10use bytes::Bytes;
11use miette::Diagnostic;
12use std::path::PathBuf;
13use thiserror::Error;
14
15/// Errors related to API errors for `FSEmul`.
16#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
17pub enum FSEmulAPIError {
18	/// This DLF address is too large to be inserted.
19	#[error("DLF Address is too large ({0:016X}) to be inserted ({1:016X})")]
20	#[diagnostic(code(cat_dev::api::fsemul::dlf_address_too_large))]
21	DlfAddressTooLarge(u128, u128),
22	#[error("DLF Paths _MUST_ be able tto be encoded as UTF-8, this file path was not: {0:02X?}")]
23	#[diagnostic(code(cat_dev::api::fsemul::dlf_path_forced_utf8))]
24	DlfPathMustBeUtf8(Bytes),
25	/// DLF files do mandate that we have the end of a file which is represented
26	/// as the last address in the file.
27	#[error("DLF files must have an ending address that appears _last_, and is an empty string.")]
28	#[diagnostic(code(cat_dev::api::fsemul::dlf_must_have_ending))]
29	DlfMustHaveEnding,
30	#[error("You tried to place a disk item past the current ending, please update the ending, before updating the new item.")]
31	#[diagnostic(code(cat_dev::api::fsemul::dlf_update_ending_first))]
32	DlfUpsertEndingFirst,
33	#[error("Failed to interact with path, file must be open first: {0:?}")]
34	#[diagnostic(code(cat_dev::api::fsemul::path_not_open))]
35	PathNotOpen(PathBuf),
36	#[error(transparent)]
37	#[diagnostic(transparent)]
38	PCFS(#[from] PCFSApiError),
39}
40
41impl From<FSEmulAPIError> for CatBridgeError {
42	fn from(value: FSEmulAPIError) -> Self {
43		Self::API(value.into())
44	}
45}
46
47impl From<PCFSApiError> for APIError {
48	fn from(value: PCFSApiError) -> Self {
49		Self::FSEmul(value.into())
50	}
51}
52impl From<PCFSApiError> for CatBridgeError {
53	fn from(value: PCFSApiError) -> Self {
54		Self::API(value.into())
55	}
56}
57
58/// Errors dealing with the filesystem specifically related to
59#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
60pub enum FSEmulFSError {
61	/// We cannot find a path to store our `FSEmul` configuration.
62	#[error(
63		"We can't find the path to store fsemul configuration, please use explicit paths instead."
64	)]
65	#[diagnostic(code(cat_dev::fs::fsemul::cant_find_path))]
66	CantFindPath,
67	/// We cannot find the root `CAFE_SDK` path.
68	#[error("We can't find the root Cafe SDK directory, please use explicit paths instead.")]
69	#[diagnostic(code(cat_dev::fs::fsemul::cant_find_cafe_sdk_path))]
70	CantFindCafeSdkPath,
71	/// The passed in Cafe SDK path did not have the appropriate directories.
72	#[error("The Cafe SDK Path does not have the appropriate MLC path directories.")]
73	#[diagnostic(code(cat_dev::fs::fsemul::corrupt_cafe_sdk_path))]
74	CafeSdkPathCorrupt,
75	/// A DLF file contained a very invalid line.
76	#[error("While parsing a disk layout file we ran into a line which is not in the format of: `<hex address>,\"<path>\"`: {0}")]
77	#[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_line))]
78	DlfCorruptLine(String),
79	/// A DLF file contained a bad termination line.
80	#[error("DLF files must have a blank final line, but was: {0}")]
81	#[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_final_line))]
82	DlfCorruptFinalLine(String),
83	/// A DLF file had a bad version string file.
84	#[error("While parsing a disk layout file, the first line should be a version string (e.g. `v1.00`), which this was not: {0}")]
85	#[diagnostic(code(cat_dev::fs::fsemul::corrupt_dlf_version_line))]
86	DlfCorruptVersionLine(String),
87}
88impl From<FSEmulFSError> for CatBridgeError {
89	fn from(value: FSEmulFSError) -> Self {
90		Self::FS(value.into())
91	}
92}
93
94/// Errors related to protocols for `FSEmul`.
95#[derive(Diagnostic, Error, Debug, PartialEq, Eq)]
96pub enum FSEmulProtocolError {
97	#[error(transparent)]
98	#[diagnostic(transparent)]
99	PCFSSata(#[from] SataProtocolError),
100	#[error(transparent)]
101	#[diagnostic(transparent)]
102	SDIO(#[from] SDIOProtocolError),
103}
104
105impl From<FSEmulProtocolError> for NetworkError {
106	fn from(value: FSEmulProtocolError) -> Self {
107		Self::Parse(value.into())
108	}
109}
110impl From<FSEmulProtocolError> for CatBridgeError {
111	fn from(value: FSEmulProtocolError) -> Self {
112		Self::Network(value.into())
113	}
114}
115
116impl From<SataProtocolError> for NetworkParseError {
117	fn from(value: SataProtocolError) -> Self {
118		Self::FSEmul(value.into())
119	}
120}
121impl From<SataProtocolError> for NetworkError {
122	fn from(value: SataProtocolError) -> Self {
123		Self::Parse(value.into())
124	}
125}
126impl From<SataProtocolError> for CatBridgeError {
127	fn from(value: SataProtocolError) -> Self {
128		Self::Network(value.into())
129	}
130}
131
132impl From<SDIOProtocolError> for NetworkParseError {
133	fn from(value: SDIOProtocolError) -> Self {
134		Self::FSEmul(value.into())
135	}
136}
137impl From<SDIOProtocolError> for NetworkError {
138	fn from(value: SDIOProtocolError) -> Self {
139		Self::Parse(value.into())
140	}
141}
142impl From<SDIOProtocolError> for CatBridgeError {
143	fn from(value: SDIOProtocolError) -> Self {
144		Self::Network(value.into())
145	}
146}