aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-15 15:43:08 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-15 15:43:08 +0100
commit2049aed8044e2ddc482ab772b8cd4bd58849e2a0 (patch)
tree02cc49b513426016a7e3f4ef9c9e52353e4a0b13
parent7f71249f4bd23225f8d74a921a463170d121d9b0 (diff)
prettify error messages
-rw-r--r--src/error.rs24
-rw-r--r--src/main.rs6
2 files changed, 15 insertions, 15 deletions
diff --git a/src/error.rs b/src/error.rs
index 7f44d4c..1812073 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -15,31 +15,31 @@ pub enum Error {
NoAddrRequested,
#[error("missing client id")]
NoClientId,
- #[error("no ipv4 addr on interface {0}")]
+ #[error("no ipv4 address on interface {0}")]
NoIpv4Addr(String),
#[error("missing message type")]
NoMsgType,
- #[error("bytes sent not equal to pkt size")]
- PartialResponse,
- #[error("addr pool exhausted")]
+ #[error("failed to send whole packet (expected {0}, got {1})")]
+ PartialSend(usize, usize),
+ #[error("address pool exhausted")]
PoolExhausted,
- #[error("ip addr parse error")]
+ #[error("can't parse network address: {0}")]
AddrParseError(#[from] net::AddrParseError),
- #[error("ffi nul error (string contains nul bytes)")]
- FfiNulError(#[from] ffi::NulError),
- #[error("io error")]
+ #[error("string contains nul bytes: {0}")]
+ Nul(#[from] ffi::NulError),
+ #[error("io error: {0}")]
Io(#[from] io::Error),
- #[error("dhcproto decode error")]
+ #[error("dhcproto decode error: {0}")]
DhcprotoDecode(#[from] dhcproto::error::DecodeError),
- #[error("dhcproto encode error")]
+ #[error("dhcproto encode error: {0}")]
DhcprotoEncode(#[from] dhcproto::error::EncodeError),
- #[error("linkaddrs error")]
+ #[error("linkaddrs error: {0}")]
LinkAddrs(#[from] linkaddrs::Error),
#[error("netlinklib error: {0}")]
Netlinklib(#[from] rsdsl_netlinklib::Error),
- #[error("serde_json error")]
+ #[error("serde_json error: {0}")]
SerdeJson(#[from] serde_json::Error),
}
diff --git a/src/main.rs b/src/main.rs
index 368e143..adf61d0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -185,7 +185,7 @@ fn handle_request<T: LeaseManager>(
let n = sock.send_to(&resp_buf, &dst.into())?;
if n != resp_buf.len() {
- Err(Error::PartialResponse)
+ Err(Error::PartialSend(resp_buf.len(), n))
} else {
println!(
"[info] offer {} client id {} lease time {:?} on {}",
@@ -253,7 +253,7 @@ fn handle_request<T: LeaseManager>(
let n = sock.send_to(&resp_buf, &dst.into())?;
if n != resp_buf.len() {
- return Err(Error::PartialResponse);
+ return Err(Error::PartialSend(resp_buf.len(), n));
} else if renew {
println!(
"[info] nak {} client id {} on {} (renew)",
@@ -295,7 +295,7 @@ fn handle_request<T: LeaseManager>(
let n = sock.send_to(&resp_buf, &dst.into())?;
if n != resp_buf.len() {
- return Err(Error::PartialResponse);
+ return Err(Error::PartialSend(resp_buf.len(), n));
} else if renew {
println!(
"[info] ack {} client id {} lease time {:?} on {} (renew)",