mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-12 16:02:56 +00:00
This patch aims to fix some of the inconsistencies in error reporting, for example "Internal error" or "Console request failed" instead of "password authentication failed for user '<NAME>'".
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use std::{error::Error as StdError, fmt, io};
|
|
|
|
/// Upcast (almost) any error into an opaque [`io::Error`].
|
|
pub fn io_error(e: impl Into<Box<dyn StdError + Send + Sync>>) -> io::Error {
|
|
io::Error::new(io::ErrorKind::Other, e)
|
|
}
|
|
|
|
/// A small combinator for pluggable error logging.
|
|
pub fn log_error<E: fmt::Display>(e: E) -> E {
|
|
tracing::error!("{e}");
|
|
e
|
|
}
|
|
|
|
/// Marks errors that may be safely shown to a client.
|
|
/// This trait can be seen as a specialized version of [`ToString`].
|
|
///
|
|
/// NOTE: This trait should not be implemented for [`anyhow::Error`], since it
|
|
/// is way too convenient and tends to proliferate all across the codebase,
|
|
/// ultimately leading to accidental leaks of sensitive data.
|
|
pub trait UserFacingError: fmt::Display {
|
|
/// Format the error for client, stripping all sensitive info.
|
|
///
|
|
/// Although this might be a no-op for many types, it's highly
|
|
/// recommended to override the default impl in case error type
|
|
/// contains anything sensitive: various IDs, IP addresses etc.
|
|
#[inline(always)]
|
|
fn to_string_client(&self) -> String {
|
|
self.to_string()
|
|
}
|
|
}
|