|
1 | 1 | use alloc::{borrow::ToOwned, string::String}; |
2 | 2 | use core::fmt::{Display, Formatter}; |
3 | | -use derive_more::From; |
4 | | -use smoltcp::socket::{ |
5 | | - tcp::{self, ConnectError, RecvError}, |
6 | | - udp::{self, BindError}, |
7 | | -}; |
| 3 | +use gpt_disk_io::gpt_disk_types; |
8 | 4 |
|
9 | 5 | pub type Result<T, E = Error> = core::result::Result<T, E>; |
10 | 6 |
|
11 | | -#[derive(Debug, From)] |
12 | | -pub enum Error { |
13 | | - Connect(#[from] ConnectError), |
14 | | - TcpSend(#[from] tcp::SendError), |
15 | | - UdpSend(#[from] udp::SendError), |
16 | | - Recv(#[from] RecvError), |
17 | | - Bind(#[from] BindError), |
18 | | - Postcard(#[from] postcard::Error), |
19 | | - Uefi(#[from] uefi::Error), |
20 | | - Generic(String), |
21 | | -} |
| 7 | +#[derive(Debug)] |
| 8 | +pub struct Error(pub String); |
22 | 9 |
|
23 | 10 | impl Error { |
24 | 11 | pub fn msg(s: &str) -> Error { |
25 | | - Error::Generic(s.to_owned()) |
| 12 | + Self(s.to_owned()) |
26 | 13 | } |
27 | 14 | } |
28 | 15 |
|
| 16 | +macro_rules! err { |
| 17 | + ($ty: ty) => { |
| 18 | + impl From<$ty> for Error { |
| 19 | + fn from(value: $ty) -> Self { |
| 20 | + Self(format!("{}: {value}", stringify!($ty))) |
| 21 | + } |
| 22 | + } |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +err!(uefi::Error); |
| 27 | +err!(smoltcp::socket::tcp::ConnectError); |
| 28 | +err!(smoltcp::socket::tcp::RecvError); |
| 29 | +err!(smoltcp::socket::tcp::SendError); |
| 30 | +err!(smoltcp::socket::udp::BindError); |
| 31 | +err!(smoltcp::socket::udp::SendError); |
| 32 | +err!(postcard::Error); |
| 33 | +err!(lz4_flex::block::DecompressError); |
| 34 | +err!(gpt_disk_io::DiskError<Error>); |
| 35 | +err!(gpt_disk_types::GptPartitionEntrySizeError); |
| 36 | + |
29 | 37 | impl Display for Error { |
30 | 38 | fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), core::fmt::Error> { |
31 | 39 | write!(fmt, "{self:?}") |
|
0 commit comments