From 4c56ba1e25a07ebe9dc0c7258987d2b486065412 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Thu, 5 May 2022 11:25:16 -0400 Subject: [PATCH] fix: Move ErrorLogger trait to the only place it's used --- data_types/src/error.rs | 30 --------------------------- data_types/src/lib.rs | 1 - service_grpc_influxrpc/src/service.rs | 27 +++++++++++++++++++++++- 3 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 data_types/src/error.rs diff --git a/data_types/src/error.rs b/data_types/src/error.rs deleted file mode 100644 index ef7131298b..0000000000 --- a/data_types/src/error.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Common error utilities -use std::fmt::Debug; - -use observability_deps::tracing::error; - -/// Add ability for Results to log error messages via `error!` logs. -/// This is useful when using async tasks that may not have any code -/// checking their return values. -pub trait ErrorLogger { - /// Log the contents of self with a string of context. The context - /// should appear in a message such as - /// - /// "Error : - fn log_if_error(self, context: &str) -> Self; - - /// Provided method to log an error via the `error!` macro - fn log_error(context: &str, e: E) { - error!("Error {}: {:?}", context, e); - } -} - -/// Implement logging for all results -impl ErrorLogger for Result { - fn log_if_error(self, context: &str) -> Self { - if let Err(e) = &self { - Self::log_error(context, e); - } - self - } -} diff --git a/data_types/src/lib.rs b/data_types/src/lib.rs index 29f1a56182..bd3a990d97 100644 --- a/data_types/src/lib.rs +++ b/data_types/src/lib.rs @@ -12,7 +12,6 @@ pub mod chunk_metadata; pub mod consistent_hasher; -pub mod error; pub mod job; pub mod partition_metadata; pub mod timestamp; diff --git a/service_grpc_influxrpc/src/service.rs b/service_grpc_influxrpc/src/service.rs index 3e06d80c98..ca0c2ab29b 100644 --- a/service_grpc_influxrpc/src/service.rs +++ b/service_grpc_influxrpc/src/service.rs @@ -11,7 +11,6 @@ use crate::{ input::GrpcInputs, StorageService, }; -use data_types::error::ErrorLogger; use data_types2::{org_and_bucket_to_database, DatabaseName}; use generated_types::{ google::protobuf::Empty, literal_or_regex::Value as RegexOrLiteralValue, @@ -1363,6 +1362,32 @@ where Box::new(DeferredToJson { s: s.clone() }) } +/// Add ability for Results to log error messages via `error!` logs. +/// This is useful when using async tasks that may not have any code +/// checking their return values. +pub trait ErrorLogger { + /// Log the contents of self with a string of context. The context + /// should appear in a message such as + /// + /// "Error : + fn log_if_error(self, context: &str) -> Self; + + /// Provided method to log an error via the `error!` macro + fn log_error(context: &str, e: E) { + error!("Error {}: {:?}", context, e); + } +} + +/// Implement logging for all results +impl ErrorLogger for Result { + fn log_if_error(self, context: &str) -> Self { + if let Err(e) = &self { + Self::log_error(context, e); + } + self + } +} + #[cfg(test)] mod tests { use super::*;