pub trait ForgeError:
Error
+ Send
+ Sync
+ 'static {
// Required methods
fn kind(&self) -> &'static str;
fn caption(&self) -> &'static str;
// Provided methods
fn is_retryable(&self) -> bool { ... }
fn is_fatal(&self) -> bool { ... }
fn status_code(&self) -> u16 { ... }
fn exit_code(&self) -> i32 { ... }
fn user_message(&self) -> String { ... }
fn dev_message(&self) -> String { ... }
fn backtrace(&self) -> Option<&Backtrace> { ... }
fn register(&self) { ... }
}Expand description
Base trait for all custom error variants.
Required Methods§
Provided Methods§
Sourcefn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
Returns true if the operation can be retried
Sourcefn status_code(&self) -> u16
fn status_code(&self) -> u16
Returns an appropriate HTTP status code for the error
Sourcefn user_message(&self) -> String
fn user_message(&self) -> String
Returns a message that is safe to show to end users.
The default is the error’s caption: fixed
text per kind that never carries the error’s data. Display,
dev_message and Debug do carry it (file
paths, endpoints with any credentials in them, source errors,
field values), so keep those for logs. Override this method to
show a message you have checked is safe, such as a validation
hint.
Until 1.1.0 the default was the full Display text, which is
not safe to show.
§Example
use error_forge::{AppError, ForgeError};
let error = AppError::network("https://user:secret@db.internal/prod", None);
assert!(!error.user_message().contains("secret"));
assert!(error.to_string().contains("db.internal"));Sourcefn dev_message(&self) -> String
fn dev_message(&self) -> String
Returns a detailed technical message for developers/logs
Sourcefn register(&self)
fn register(&self)
Fires the registered error hook (see
try_register_error_hook)
with this error’s caption, kind and flags.
Despite the name, nothing is stored: this does not touch the
error-code ErrorRegistry.
AppError and define_errors! constructors already fire the
hook, so calling register on such an error fires it a second
time. It is a no-op when no hook is registered.
§Example
use error_forge::{AppError, ForgeError};
let error = AppError::config("missing key");
// Reports the error to the hook again, if one is installed.
error.register();Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".