1use http::header::InvalidHeaderValue;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug)]
5pub enum Error {
7 Tungstenite(Box<tungstenite::Error>),
8 ProcessInfo(crate::process_info::Error),
9 SerdeJson(serde_json::Error),
10 Io(std::io::Error),
11}
12
13impl Display for Error {
14 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15 match self {
16 Self::Tungstenite(e) => e.fmt(f),
17 Self::ProcessInfo(e) => e.fmt(f),
18 Self::SerdeJson(e) => e.fmt(f),
19 Self::Io(e) => e.fmt(f),
20 }
21 }
22}
23
24impl std::error::Error for Error {}
25
26impl From<std::io::Error> for Error {
27 fn from(value: std::io::Error) -> Self {
28 Self::Io(value)
29 }
30}
31
32impl From<tungstenite::Error> for Error {
33 fn from(value: tungstenite::Error) -> Self {
34 Self::Tungstenite(Box::new(value))
35 }
36}
37
38impl From<serde_json::Error> for Error {
39 fn from(value: serde_json::Error) -> Self {
40 Self::SerdeJson(value)
41 }
42}
43
44impl From<crate::process_info::Error> for Error {
45 fn from(value: crate::process_info::Error) -> Self {
46 Self::ProcessInfo(value)
47 }
48}
49
50impl From<InvalidHeaderValue> for Error {
51 fn from(value: InvalidHeaderValue) -> Self {
52 Self::Tungstenite(Box::new(tungstenite::Error::HttpFormat(
53 tungstenite::http::Error::from(value),
54 )))
55 }
56}