LCOV - differential code coverage report
Current view: top level - proxy/src - error.rs (source / functions) Coverage Total Hit UBC CBC
Current: cd44433dd675caa99df17a61b18949c8387e2242.info Lines: 35.0 % 20 7 13 7
Current Date: 2024-01-09 02:06:09 Functions: 30.8 % 13 4 9 4
Baseline: 66c52a629a0f4a503e193045e0df4c77139e344b.info
Baseline Date: 2024-01-08 15:34:46

           TLA  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 CBC           2 : pub fn io_error(e: impl Into<Box<dyn StdError + Send + Sync>>) -> io::Error {
       5               2 :     io::Error::new(io::ErrorKind::Other, e)
       6               2 : }
       7                 : 
       8                 : /// A small combinator for pluggable error logging.
       9               4 : pub fn log_error<E: fmt::Display>(e: E) -> E {
      10               4 :     tracing::error!("{e}");
      11               4 :     e
      12               4 : }
      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 UBC           0 :     fn to_string_client(&self) -> String {
      28               0 :         self.to_string()
      29               0 :     }
      30                 : }
      31                 : 
      32               0 : #[derive(Clone)]
      33                 : pub enum ErrorKind {
      34                 :     /// Wrong password, unknown endpoint, protocol violation, etc...
      35                 :     User,
      36                 : 
      37                 :     /// Network error between user and proxy. Not necessarily user error
      38                 :     Disconnect,
      39                 : 
      40                 :     /// Proxy self-imposed rate limits
      41                 :     RateLimit,
      42                 : 
      43                 :     /// internal errors
      44                 :     Service,
      45                 : 
      46                 :     /// Error communicating with control plane
      47                 :     ControlPlane,
      48                 : 
      49                 :     /// Error communicating with compute
      50                 :     Compute,
      51                 : }
      52                 : 
      53                 : impl ErrorKind {
      54               0 :     pub fn to_str(&self) -> &'static str {
      55               0 :         match self {
      56               0 :             ErrorKind::User => "request failed due to user error",
      57               0 :             ErrorKind::Disconnect => "client disconnected",
      58               0 :             ErrorKind::RateLimit => "request cancelled due to rate limit",
      59               0 :             ErrorKind::Service => "internal service error",
      60               0 :             ErrorKind::ControlPlane => "non-retryable control plane error",
      61               0 :             ErrorKind::Compute => "non-retryable compute error (or exhausted retry capacity)",
      62                 :         }
      63               0 :     }
      64                 : }
        

Generated by: LCOV version 2.1-beta