Skip to main content

msg_bail_anyhow

Macro msg_bail_anyhow 

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

return Err(...) with the message, ❌-prefixed.

use anyhow::Result;
use kasl::{msg_bail_anyhow, libs::messages::Message};

fn process_task(task_id: Option<i32>) -> Result<()> {
    let id = match task_id {
        Some(id) => id,
        None => msg_bail_anyhow!(Message::InvalidInput),
    };
    let _ = id;
    Ok(())
}
use anyhow::Result;
use kasl::{msg_bail_anyhow, libs::messages::Message};

fn secure_operation() -> Result<()> {
    if !user_has_permission() {
        msg_bail_anyhow!(Message::PermissionDenied);
    }
    Ok(())
}
use anyhow::Result;
use kasl::{msg_bail_anyhow, libs::messages::Message};

fn access_resource(path: &str) -> Result<()> {
    if !resource_exists(path) {
        msg_bail_anyhow!(Message::FileNotFound);
    }
    Ok(())
}