cdumay_error_standard

Crates.iocdumay_error_standard
lib.rscdumay_error_standard
version1.0.4
created_at2025-02-07 06:51:50.837993+00
updated_at2025-05-26 13:09:24.473268+00
descriptionA Rust Library which define standard errors
homepagehttps://github.com/cdumay/cdumay_error_standard
repositoryhttps://github.com/cdumay/cdumay_error_standard
max_upload_size
id1546580
size12,741
Cédric Dumay (cdumay)

documentation

https://docs.rs/cdumay_error_standard

README

cdumay_error_standard

License: BSD-3-Clause cdumay_error_standard on crates.io cdumay_error_standard on docs.rs Source Code Repository

A collection of standard error types and error kinds commonly used in Rust applications. This crate provides predefined error types and kinds using the cdumay_core framework.

Features

  • Common error types for IO operations and unexpected errors
  • Easy integration with the cdumay_core framework

Examples

use cdumay_error_standard::{FileNotExists, Unexpected};
use std::path::Path;
use cdumay_core::Result;

// Creating a FileNotExists error
fn check_file(path: &Path) -> Result<()> {
    if !path.exists() {
        return Result::Err(FileNotExists::new().with_message(format!(
            "File {} does not exist",
            path.display()
        )).into());
    }
    Ok(())
}

// Using Unexpected error for runtime errors
// Note: We use From<std::result::Result> to return cdumay_core::Result
fn divide(a: i32, b: i32) -> Result<i32> {
    if b == 0 {
        return Err(Unexpected::new().with_message("Division by zero".into()).into());
    }
    Ok(a / b)
}

Error Handling

All errors implement the Into<Error>, providing consistent error handling across your application:

use cdumay_error_standard::FileRead;
use cdumay_core::Result;

fn read_content() -> Result<String> {
    let err = FileRead::new().with_message("Failed to read config file".into());

    // Access error properties
    println!("Error code: {}", err.code());
    println!("Message: {}", err.message());

    Err(err.into())
}
Commit count: 9

cargo fmt