debug_error

Crates.iodebug_error
lib.rsdebug_error
version0.1.0
created_at2025-08-29 20:41:32.555942+00
updated_at2025-08-29 20:41:32.555942+00
descriptionLightweight error handling library, which automatically captures the location (file and line)
homepage
repositoryhttps://github.com/OHUVERSE/Rust-Debug-Error
max_upload_size
id1816861
size26,137
Mr. Ohu (OHUVERSE)

documentation

README

debug_error

Crates.io Docs.rs GitHub Repo

A lightweight error handling library for Rust that automatically captures file and line information, making debugging significantly easier.

Features

  • 📍 Automatic Location Tracking - Errors automatically capture file and line numbers
  • 📝 Flexible Logging - Choose between automatic logging or manual control
  • 🔧 Seamless Integration - Works perfectly with Rust's ? operator
  • 🚀 High compatibility - Compatible with any logger that implements the log crate interface
  • 📦 Lightweight - Minimal performance overhead

Example output

[2025-08-28T13:54:40Z ERROR basic_usage] Created error: This is a test error without automatic logging at examples\basic_usage.rs:37:15
[2025-08-28T13:58:16Z ERROR basic_usage] Error: This error is automatically logged at examples\basic_usage.rs:48:5

Example usage

use debug_error::{DebugError, debug_error, debug_error_with_log};
use log::info;

fn main() -> Result<(), DebugError> {
    // Initialize your logger (env_logger, pretty_env_logger, etc.)
    env_logger::init();
    
    info!("Starting application");
    
    // This will return an error with location information
    let result = might_fail()?;
    
    Ok(())
}

fn might_fail() -> Result<(), DebugError> {
    if some_condition() {
        // Automatically logs the error and includes location
        Err(debug_error_with_log!("Operation failed due to condition"))?
    }
    
    Ok(())
}

fn some_condition() -> bool {
    true
}

Notes

  • More Examples:
    • examples/basic_usage.rs
    • examples/real_world_scenario.rs
  • How to use:
    • Use the "debug_error_with_log" macro during development - no need for error handling infrastructure yet.
    • Replace "debug_error_with_log" macro with "debug_error" - for production and when error handling infrastructure is set up.

Installation

Add to your Cargo.toml:

[dependencies]
debug_error = "0.1"
log = "0.4"  # Required for logging functionality
Commit count: 1

cargo fmt