Skip to main content

msg_error

Macro msg_error 

Source
macro_rules! msg_error {
    ($msg:expr) => { ... };
    ($msg:expr, true) => { ... };
}
Expand description

Prints an error message with ❌ prefix and automatic routing.

This macro handles error message display with appropriate severity level routing. In debug mode, errors are logged through the tracing system, while in normal mode they’re displayed on stderr for proper error handling.

§Visual Design

  • Prefix: ❌ (red X emoji)
  • Purpose: Error notifications and failure messages
  • Stream: Uses stderr in normal mode for proper error stream handling

§Output Routing

  • Debug Mode: Uses tracing::error! for structured error logging
  • Normal Mode: Uses eprintln! to write to stderr

§Error Stream Benefits

Using stderr for error output provides several advantages:

  • Stream Separation: Errors don’t interfere with normal output
  • Script Compatibility: Scripts can separate errors from data
  • Shell Redirection: Users can redirect errors independently
  • Log Aggregation: Error logs can be collected separately

§Usage Patterns

§Simple Error Message

msg_error!(Message::TaskNotFound);
// Output to stderr: "❌ Task not found"

§Error Message with Line Breaks

msg_error!(Message::ConfigParseError, true);
// Output to stderr: "\n❌ Failed to parse configuration file\n"