From 38380198e1660348e54cc69a6355bcd1f92e8cae Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Mon, 19 May 2025 09:45:44 +0200 Subject: [PATCH] misc: api_client: streamline #[source] and Error This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- api_client/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api_client/src/lib.rs b/api_client/src/lib.rs index 6bc36e650..108d4382c 100644 --- a/api_client/src/lib.rs +++ b/api_client/src/lib.rs @@ -12,15 +12,15 @@ use vmm_sys_util::sock_ctrl_msg::ScmSocket; #[derive(Debug, Error)] pub enum Error { #[error("Error writing to or reading from HTTP socket: {0}")] - Socket(std::io::Error), + Socket(#[source] std::io::Error), #[error("Error sending file descriptors: {0}")] - SocketSendFds(vmm_sys_util::errno::Error), + SocketSendFds(#[source] vmm_sys_util::errno::Error), #[error("Error parsing HTTP status code: {0}")] - StatusCodeParsing(std::num::ParseIntError), + StatusCodeParsing(#[source] std::num::ParseIntError), #[error("HTTP output is missing protocol statement")] MissingProtocol, #[error("Error parsing HTTP Content-Length field: {0}")] - ContentLengthParsing(std::num::ParseIntError), + ContentLengthParsing(#[source] std::num::ParseIntError), #[error("Server responded with an error: {0:?}: {1:?}")] ServerResponse(StatusCode, Option), }