calltrace-rs 1.1.4

High-performance function call tracing library for C/C++ applications using GCC instrumentation with Rust safety guarantees
Documentation
//! Error handling for CallTrace library

use thiserror::Error;

#[derive(Error, Debug)]
pub enum CallTraceError {
    #[error("Memory allocation failed")]
    OutOfMemory,

    #[error("Invalid argument: {0}")]
    InvalidArgument(String),

    #[error("DWARF parsing error: {0}")]
    DwarfError(String),

    #[error("Register capture failed: {0}")]
    RegisterError(String),

    #[error("JSON serialization error: {0}")]
    JsonError(#[from] serde_json::Error),

    #[error("Thread operation failed: {0}")]
    ThreadError(String),

    #[error("Not supported on this architecture")]
    NotSupported,

    #[error("Initialization failed: {0}")]
    InitializationError(String),
    // TODO(human): Add more error types as needed
}

pub type Result<T> = std::result::Result<T, CallTraceError>;

/// Convert to C-compatible error code
impl CallTraceError {
    pub fn to_c_code(&self) -> i32 {
        match self {
            CallTraceError::OutOfMemory => -1,
            CallTraceError::InvalidArgument(_) => -2,
            CallTraceError::DwarfError(_) => -3,
            CallTraceError::RegisterError(_) => -4,
            CallTraceError::JsonError(_) => -5,
            CallTraceError::ThreadError(_) => -6,
            CallTraceError::NotSupported => -7,
            CallTraceError::InitializationError(_) => -8,
        }
    }
}