LoggableError

Trait LoggableError 

Source
pub trait LoggableError {
    // Required methods
    fn log_error<S: Send + Sync + Display + 'static>(self, context: S);
    fn log_warning<S: Send + Sync + Display + 'static>(self, context: S);
    fn log_debug<S: Send + Sync + Display + 'static>(self, context: S);
}
Expand description

A trait that allows printing the entire error chain of an Error (it is implemented for anyhow::Error) along with a custom context message.

This reduces the need for custom error printing code and ensures consistency across log messages.

§Example

The following code will log user-facing message - low level error as an error.

use anyhow::anyhow;
use snarkvm_utilities::LoggableError;

let my_error = anyhow!("low level problem");
my_error.log_error("user-facing message");

Required Methods§

Source

fn log_error<S: Send + Sync + Display + 'static>(self, context: S)

Log the error with the given context and log level ERROR.

Source

fn log_warning<S: Send + Sync + Display + 'static>(self, context: S)

Log the error with the given context and log level WARNING.

Source

fn log_debug<S: Send + Sync + Display + 'static>(self, context: S)

Log the error with the given context and log level DEBUG.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§