use ohno::enrich_err;
#[ohno::error]
#[from(std::io::Error)]
#[display("Database error (1)")]
struct DatabaseError;
#[ohno::error]
#[from(DatabaseError)]
#[display("Service error (2)")]
struct ServiceError;
#[ohno::error]
#[from(ServiceError)]
#[display("API error (3)")]
struct ApiError;
#[enrich_err("connecting to database (1.1)")]
#[enrich_err("validating credentials (1.2)")]
#[enrich_err("establishing connection pool (1.3)")]
fn database_operation() -> Result<String, DatabaseError> {
Err(std::io::Error::new(std::io::ErrorKind::PermissionDenied, "access denied (0)").into())
}
#[enrich_err("fetching user data (2.1)")]
#[enrich_err("parsing user profile (2.2)")]
#[enrich_err("validating user permissions (2.3)")]
fn service_operation() -> Result<String, ServiceError> {
Ok(database_operation()?)
}
#[enrich_err("handling API request (3.1)")]
#[enrich_err("processing request payload (3.2)")]
#[enrich_err("preparing response (3.3)")]
fn api_operation() -> Result<String, ApiError> {
Ok(service_operation()?)
}
#[expect(clippy::unwrap_used, reason = "Example code")]
fn main() {
let error = api_operation().unwrap_err();
println!("{error}");
}