UserFriendlyError

Trait UserFriendlyError 

Source
pub trait UserFriendlyError: Display + Debug {
    // Required methods
    fn user_message(&self) -> String;
    fn developer_message(&self) -> String;
    fn support_code(&self) -> String;
    fn severity(&self) -> ErrorSeverity;

    // Provided methods
    fn suggested_actions(&self) -> Vec<String> { ... }
    fn is_retryable(&self) -> bool { ... }
}
Expand description

Trait providing user-friendly error messaging at multiple levels.

This trait ensures all errors provide appropriate messages for different audiences while maintaining security and consistency. Provides a consistent, multi-level error messaging interface across the crate.

Implementors must supply user-safe text via user_message and richer context for logs and support via developer_message and support_code. The severity, suggested_actions, and is_retryable methods help downstream handling and UX. See each method for audience and usage guidance.

Required Methods§

Source

fn user_message(&self) -> String

User-facing message that is clear, actionable, and non-technical.

This message should:

  • Use plain language that any user can understand
  • Provide actionable guidance when possible
  • Never leak sensitive information
  • Be empathetic and helpful in tone
§Examples
  • “We’re experiencing technical difficulties. Please try again in a moment.”
  • “Your session has expired. Please sign in again to continue.”
  • “There’s an issue with your account. Please contact our support team.”
Source

fn developer_message(&self) -> String

Technical message with detailed information for developers and logs.

This message should:

  • Include precise technical details
  • Provide context for debugging
  • Include relevant identifiers and parameters
  • Be structured for parsing by monitoring tools
Source

fn support_code(&self) -> String

Unique support reference code for customer service and troubleshooting.

This code should:

  • Be unique and easily communicable
  • Allow support teams to identify the exact error
  • Not contain sensitive information
  • Be consistent across error instances
Source

fn severity(&self) -> ErrorSeverity

Error severity level for proper handling and alerting.

Provided Methods§

Source

fn suggested_actions(&self) -> Vec<String>

Suggested user actions for resolving the error.

Source

fn is_retryable(&self) -> bool

Whether this error should be retryable by the user.

Implementors§