From 1f90b27d34ab0c534f94b56d7241411bdd468029 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 00:48:16 +0300 Subject: [PATCH] feat: Add ErrorContext trait implementation for anyhow::Result to enable context error handling with ChargingError conversion - Add ChargingError import from super::types - Add ErrorContext implementation for anyhow::Result with with_context method that maps errors to ChargingError::InternalError with formatted context message --- apps/charging-engine/src/errors/helpers.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/charging-engine/src/errors/helpers.rs b/apps/charging-engine/src/errors/helpers.rs index ee2606e..caa3fe1 100644 --- a/apps/charging-engine/src/errors/helpers.rs +++ b/apps/charging-engine/src/errors/helpers.rs @@ -1,11 +1,20 @@ use anyhow::Context; +use super::types::ChargingError; + pub type ChargingResult = Result; pub trait ErrorContext { fn with_context(self, msg: &str) -> ChargingResult; } +impl ErrorContext for anyhow::Result { + fn with_context(self, msg: &str) -> ChargingResult { + self.map_err(|e| ChargingError::InternalError(format!("{}: {}", msg, e))) + .map_err(|e| e.into()) + } +} + impl ErrorContext for Result where E: Into,