fix: Move ErrorLogger trait to the only place it's used
parent
fb8f8d22c0
commit
4c56ba1e25
|
@ -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 <context>: <formatted error message>
|
||||
fn log_if_error(self, context: &str) -> Self;
|
||||
|
||||
/// Provided method to log an error via the `error!` macro
|
||||
fn log_error<E: Debug>(context: &str, e: E) {
|
||||
error!("Error {}: {:?}", context, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement logging for all results
|
||||
impl<T, E: Debug> ErrorLogger for Result<T, E> {
|
||||
fn log_if_error(self, context: &str) -> Self {
|
||||
if let Err(e) = &self {
|
||||
Self::log_error(context, e);
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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 <context>: <formatted error message>
|
||||
fn log_if_error(self, context: &str) -> Self;
|
||||
|
||||
/// Provided method to log an error via the `error!` macro
|
||||
fn log_error<E: std::fmt::Debug>(context: &str, e: E) {
|
||||
error!("Error {}: {:?}", context, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement logging for all results
|
||||
impl<T, E: std::fmt::Debug> ErrorLogger for Result<T, E> {
|
||||
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::*;
|
||||
|
|
Loading…
Reference in New Issue