aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock21
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs51
3 files changed, 40 insertions, 33 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 51c00a9..ae29ba2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1115,7 +1115,6 @@ dependencies = [
"rustls-pemfile",
"serde",
"sysinfo",
- "thiserror",
]
[[package]]
@@ -1311,26 +1310,6 @@ dependencies = [
]
[[package]]
-name = "thiserror"
-version = "1.0.69"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
-dependencies = [
- "thiserror-impl",
-]
-
-[[package]]
-name = "thiserror-impl"
-version = "1.0.69"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
name = "time"
version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 113c840..98cd41f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,4 +16,3 @@ rustls = { version = "0.20.0", default-features = false }
rustls-pemfile = "1.0.2"
serde = { version = "1.0", features = ["derive"] }
sysinfo = { version = "0.29.10", default-features = false }
-thiserror = "1.0"
diff --git a/src/main.rs b/src/main.rs
index 91dfde1..7859c4e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+use std::fmt;
use std::fs::{self, File, OpenOptions};
use std::io::{self, BufReader, Write};
use std::os::unix::fs::{MetadataExt, PermissionsExt};
@@ -15,31 +16,59 @@ use rustls::{Certificate, PrivateKey, ServerConfig};
use rustls_pemfile::{certs, pkcs8_private_keys};
use serde::Deserialize;
use sysinfo::{Pid, ProcessExt, Signal, System, SystemExt};
-use thiserror::Error;
#[allow(non_upper_case_globals)]
const KiB: usize = 1024;
#[allow(non_upper_case_globals)]
const MiB: usize = 1024 * KiB;
-#[derive(Debug, Error)]
+#[derive(Debug)]
pub enum Error {
- #[error("can't find disk device")]
NoDiskDev,
- #[error("no private keys found in file")]
NoPrivateKeys,
- #[error("no rootfs set in active cmdline")]
RootdevUnset,
- #[error("io error: {0}")]
- Io(#[from] io::Error),
+ Io(io::Error),
- #[error("actix_web error: {0}")]
- ActixWeb(#[from] actix_web::Error),
- #[error("rustls error: {0}")]
- Rustls(#[from] rustls::Error),
+ ActixWeb(actix_web::Error),
+ Rustls(rustls::Error),
}
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::NoDiskDev => write!(f, "can't find disk device")?,
+ Self::NoPrivateKeys => write!(f, "no private keys found in file")?,
+ Self::RootdevUnset => write!(f, "no rootfs set in active cmdline")?,
+ Self::Io(e) => write!(f, "io error: {}", e)?,
+ Self::ActixWeb(e) => write!(f, "actix_web error: {}", e)?,
+ Self::Rustls(e) => write!(f, "rustls error: {}", e)?,
+ }
+
+ Ok(())
+ }
+}
+
+impl From<io::Error> for Error {
+ fn from(e: io::Error) -> Error {
+ Error::Io(e)
+ }
+}
+
+impl From<actix_web::Error> for Error {
+ fn from(e: actix_web::Error) -> Error {
+ Error::ActixWeb(e)
+ }
+}
+
+impl From<rustls::Error> for Error {
+ fn from(e: rustls::Error) -> Error {
+ Error::Rustls(e)
+ }
+}
+
+impl std::error::Error for Error {}
+
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Clone, Debug, Deserialize)]