Skip to main content

error

Function error 

Source
pub fn error(msg: Message) -> String
Expand description

Creates an error message with a red X prefix.

This function provides a standardized way to format error messages throughout the application. It ensures consistent visual presentation for error conditions and failure notifications, helping users quickly identify and understand problems.

§Visual Format

Error messages are prefixed with a red X (❌) to provide immediate visual indication of error conditions. This creates a consistent user experience for error reporting across all application areas.

§Error Message Philosophy

Error messages created by this function follow these principles:

  • Clear Problem Description: Explain what went wrong
  • Helpful Context: Provide relevant details for troubleshooting
  • Action Guidance: Suggest next steps when possible
  • Non-Technical Language: Avoid intimidating technical jargon

§Usage Context

This function is typically used for:

  • Operation failures and exceptions
  • Validation errors and invalid input
  • Configuration problems and conflicts
  • External service communication failures
  • File system and permission errors

§Arguments

  • msg - A Message enum variant containing the error details

§Returns

Returns a formatted string with the error prefix and message text.

§Examples

use kasl::libs::messages::{Message, error};

// Format a simple error message
let message = error(Message::ConfigSaveError);
println!("{}", message); // "❌ Failed to save configuration"

// With error details
let detailed_error = error(Message::GitlabFetchFailed("Network timeout".to_string()));
println!("{}", detailed_error); // "❌ [kasl] Failed to get GitLab events: Network timeout"

§Error Handling Integration

This function integrates with the application’s error handling:

use kasl::msg_error;
use kasl::libs::messages::Message;
use anyhow::Result;

fn save_config() -> Result<()> {
    // ... operation that might fail
    if let Err(_) = operation() {
        msg_error!(Message::ConfigSaveError);
        return Err(anyhow::anyhow!("Configuration save failed"));
    }
    Ok(())
}