Crates.io | cdumay_error |
lib.rs | cdumay_error |
version | 2.0.1 |
created_at | 2024-06-21 08:25:19.075333+00 |
updated_at | 2025-06-19 08:38:52.767097+00 |
description | A Rust Library which define standard errors |
homepage | https://github.com/cdumay/cdumay_error |
repository | https://github.com/cdumay/cdumay_error |
max_upload_size | |
id | 1279191 |
size | 12,518 |
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.
cdumay_core
frameworkuse cdumay_error::{FileNotExists, Unexpected};
use std::path::Path;
use cdumay_core::Result;
// Creating a FileNotExists error
fn check_file(path: &Path) -> Result<()> {
if !path.exists() {
return 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)
}
All errors implement the Into<Error>
, providing consistent error handling across your application:
use cdumay_error::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())
}