mando-lib-macro

Procedural macro crate for the Mando workspace. Provides the #[derive(ErrorCode)] macro used throughout mando-lib.

#[derive(ErrorCode)]

Auto-generates error code tracking for enum variants. Maps each variant to a static string identifier for structured error reporting and observability.

Usage

use mando_lib_macro::ErrorCode;
use thiserror::Error;
 
#[derive(Error, ErrorCode)]
pub enum DataPointError {
    #[error("path fragment '{0}' must contain...")]
    InvalidPathFragmentFormat(usize, String),
 
    #[error("data point not found: {0}")]
    NotFound(String),
}

Generated Output

impl ErrorCode for DataPointError {
    fn error_code(&self) -> &'static str {
        match self {
            Self::InvalidPathFragmentFormat(..) =>
                "crate::datapoint::DataPointError::InvalidPathFragmentFormat",
            Self::NotFound(..) =>
                "crate::datapoint::DataPointError::NotFound",
        }
    }
}

Each variant maps to a fully qualified path string, making error codes stable, unique, and grep-friendly across the codebase.

Dependencies

CratePurpose
synRust syntax parsing
quoteCode generation
proc-macro2Token stream manipulation
proc-macro-crate 3.4.0Resolves renamed crate imports

Notes

  • proc-macro-crate handles cases where mando-lib is imported under a different name
  • The macro is a proc-macro crate (lib type with proc-macro = true)
  • Used alongside thiserror for Display + std::error::Error implementations