Expand description
Error types and handling.
Defines the Error enum with variants for different error scenarios
that can occur during ORM operations.
§Error Handling Module
This module defines the error types used throughout Bottle ORM. It provides a centralized error handling system that wraps various error scenarios that can occur during database operations.
§Error Types
- InvalidData: Data validation errors (e.g., invalid format, constraint violations)
- DatabaseError: Wrapped sqlx errors (connection issues, query failures, etc.)
- InvalidArgument: Invalid arguments passed to ORM methods
§Example Usage
ⓘ
use bottle_orm::Error;
async fn create_user(db: &Database, age: i32) -> Result<User, Error> {
if age < 0 {
return Err(Error::InvalidData("Age cannot be negative".to_string()));
}
let user = User { age, /* ... */ };
db.model::<User>().insert(&user).await?;
Ok(user)
}
// Error handling
match create_user(&db, -5).await {
Ok(user) => println!("Created: {:?}", user),
Err(Error::InvalidData(msg)) => eprintln!("Validation error: {}", msg),
Err(Error::DatabaseError(e)) => eprintln!("Database error: {}", e),
Err(e) => eprintln!("Other error: {}", e),
}Enums§
- Error
- The main error type for Bottle ORM operations.