1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! [](./LICENSE)
//! [](https://crates.io/crates/cdumay_error)
//! [](https://docs.rs/cdumay_error)
//! [](https://github.com/cdumay/cdumay_error)
//!
//! 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
//!
//! ```rust
//! use 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)
//! }
//! ```
//!
//! ## Error Handling
//!
//! All errors implement the `Into<Error>`, providing consistent error handling across your application:
//!
//! ```rust
//! 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())
//! }
//! ```
use ;
define_kinds!
define_errors!