From d7c0e2488afc23f771750c18626ab85a8e505b3b Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Thu, 22 Feb 2024 09:17:14 +0100 Subject: [PATCH] Make AgentError implement std::error::Error Signed-off-by: Wiktor Kwapisiewicz --- src/error.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/error.rs b/src/error.rs index 4d0c313..5e2293a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,3 +19,15 @@ impl From for AgentError { AgentError::IO(e) } } + +impl std::fmt::Display for AgentError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AgentError::User => write!(f, "Agent: User error"), + AgentError::Proto(proto) => write!(f, "Agent: Protocol error: {}", proto), + AgentError::IO(error) => write!(f, "Agent: I/O error: {}", error), + } + } +} + +impl std::error::Error for AgentError {}