LCOV - code coverage report
Current view: top level - proxy/src - error.rs (source / functions) Coverage Total Hit
Test: 8ac049b474321fdc72ddcb56d7165153a1a900e8.info Lines: 0.0 % 10 0
Test Date: 2023-09-06 10:18:01 Functions: 0.0 % 12 0

            Line data    Source code
       1              : use std::{error::Error as StdError, fmt, io};
       2              : 
       3              : /// Upcast (almost) any error into an opaque [`io::Error`].
       4            0 : pub fn io_error(e: impl Into<Box<dyn StdError + Send + Sync>>) -> io::Error {
       5            0 :     io::Error::new(io::ErrorKind::Other, e)
       6            0 : }
       7              : 
       8              : /// A small combinator for pluggable error logging.
       9            0 : pub fn log_error<E: fmt::Display>(e: E) -> E {
      10            0 :     tracing::error!("{e}");
      11            0 :     e
      12            0 : }
      13              : 
      14              : /// Marks errors that may be safely shown to a client.
      15              : /// This trait can be seen as a specialized version of [`ToString`].
      16              : ///
      17              : /// NOTE: This trait should not be implemented for [`anyhow::Error`], since it
      18              : /// is way too convenient and tends to proliferate all across the codebase,
      19              : /// ultimately leading to accidental leaks of sensitive data.
      20              : pub trait UserFacingError: fmt::Display {
      21              :     /// Format the error for client, stripping all sensitive info.
      22              :     ///
      23              :     /// Although this might be a no-op for many types, it's highly
      24              :     /// recommended to override the default impl in case error type
      25              :     /// contains anything sensitive: various IDs, IP addresses etc.
      26              :     #[inline(always)]
      27            0 :     fn to_string_client(&self) -> String {
      28            0 :         self.to_string()
      29            0 :     }
      30              : }
        

Generated by: LCOV version 2.1-beta