macro_rules! report_attachment {
($msg:literal $(,)?) => { ... };
($context:expr $(,)?) => { ... };
($fmt:expr, $($arg:tt)*) => { ... };
}Expand description
Creates a report attachment with contextual data.
This macro creates a ReportAttachment that can be added to error reports
to provide additional context. It accepts the same arguments as the
report! macro but produces an attachment instead of a full report.
Attachments are useful for adding supplementary information to errors without changing the main error context. For example, you might attach configuration values, request parameters, or debugging information.
§Usage Modes
Like report!, this macro supports both format string mode and context
object mode. See the report! documentation for details on each mode.
§Examples
§String Attachments
use std::any::TypeId;
use rootcause::{prelude::*, report_attachment, report_attachment::ReportAttachment};
// Static string
let attachment: ReportAttachment<markers::Dynamic, markers::SendSync> =
report_attachment!("Additional context");
assert_eq!(attachment.inner_type_id(), TypeId::of::<&'static str>());
assert_eq!(
attachment.inner_handler_type_id(),
TypeId::of::<handlers::Display>()
);
// Formatted string
let attachment: ReportAttachment<markers::Dynamic, markers::SendSync> =
report_attachment!("Error occurred at line: {}", 42);
assert_eq!(attachment.inner_type_id(), TypeId::of::<String>());
assert_eq!(
attachment.inner_handler_type_id(),
TypeId::of::<handlers::Display>()
);§Structured Data Attachments
use std::any::TypeId;
use rootcause::{prelude::*, report_attachment, report_attachment::ReportAttachment};
#[derive(Debug)]
struct ErrorData {
code: i32,
message: String,
}
impl std::fmt::Display for ErrorData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Error {}: {}", self.code, self.message)
}
}
impl std::error::Error for ErrorData {}
let error_data = ErrorData {
code: 404,
message: "Not found".to_string(),
};
let attachment: ReportAttachment<ErrorData, markers::SendSync> = report_attachment!(error_data);
assert_eq!(
attachment.inner_handler_type_id(),
TypeId::of::<handlers::Display>()
);§Local (Non-Send) Attachments
use std::rc::Rc;
use rootcause::{prelude::*, report_attachment, report_attachment::ReportAttachment};
let local_data: Rc<String> = Rc::new("Local context".to_string());
let attachment: ReportAttachment<Rc<String>, markers::Local> = report_attachment!(local_data);