2026-02-12 09:41:25 +01:00
|
|
|
//! Pure domain entity errors
|
2026-02-06 20:57:00 +01:00
|
|
|
//!
|
2026-02-12 09:41:25 +01:00
|
|
|
//! This module defines domain entity-specific errors
|
|
|
|
|
//! without external framework dependencies, following
|
|
|
|
|
//! Clean Architecture principles.
|
2026-02-06 20:57:00 +01:00
|
|
|
//!
|
2026-02-12 09:41:25 +01:00
|
|
|
//! Errors manually implement `std::error::Error` and `std::fmt::Display`
|
|
|
|
|
//! to keep the domain free of external dependencies.
|
2026-02-06 20:57:00 +01:00
|
|
|
|
|
|
|
|
use std::error::Error;
|
|
|
|
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// FILE ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during File entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum FileError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Occurs when the file name contains invalid characters or is empty
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidFileName(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Occurs when validation of any entity attribute fails
|
2026-02-06 20:57:00 +01:00
|
|
|
ValidationError(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for FileError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
|
|
|
|
FileError::InvalidFileName(name) => write!(f, "Invalid file name: {}", name),
|
|
|
|
|
FileError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for FileError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for File entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type FileResult<T> = Result<T, FileError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// FOLDER ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during Folder entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum FolderError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Occurs when the folder name contains invalid characters or is empty
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidFolderName(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Occurs when validation of any entity attribute fails
|
2026-02-06 20:57:00 +01:00
|
|
|
ValidationError(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for FolderError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
|
|
|
|
FolderError::InvalidFolderName(name) => write!(f, "Invalid folder name: {}", name),
|
|
|
|
|
FolderError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for FolderError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for Folder entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type FolderResult<T> = Result<T, FolderError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// USER ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during User entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum UserError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid username
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidUsername(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid password
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidPassword(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// General validation error
|
2026-02-06 20:57:00 +01:00
|
|
|
ValidationError(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Authentication error
|
2026-02-06 20:57:00 +01:00
|
|
|
AuthenticationError(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for UserError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
2026-02-12 09:41:25 +01:00
|
|
|
UserError::InvalidUsername(msg) => write!(f, "Invalid username: {}", msg),
|
|
|
|
|
UserError::InvalidPassword(msg) => write!(f, "Invalid password: {}", msg),
|
|
|
|
|
UserError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
|
|
|
|
UserError::AuthenticationError(msg) => write!(f, "Authentication error: {}", msg),
|
2026-02-06 20:57:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for UserError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for User entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type UserResult<T> = Result<T, UserError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// SHARE ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during Share entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum ShareError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid share token
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidToken(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid expiration date
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidExpiration(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// General validation error
|
2026-02-06 20:57:00 +01:00
|
|
|
ValidationError(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for ShareError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
|
|
|
|
ShareError::InvalidToken(msg) => write!(f, "Invalid token: {}", msg),
|
|
|
|
|
ShareError::InvalidExpiration(msg) => write!(f, "Invalid expiration date: {}", msg),
|
|
|
|
|
ShareError::ValidationError(msg) => write!(f, "Validation error: {}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for ShareError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for Share entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type ShareResult<T> = Result<T, ShareError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// CALENDAR ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during Calendar entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum CalendarError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid calendar name
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidName(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid color code
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidColor(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid owner ID
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidOwnerId(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for CalendarError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
|
|
|
|
CalendarError::InvalidName(msg) => write!(f, "Invalid calendar name: {}", msg),
|
|
|
|
|
CalendarError::InvalidColor(msg) => write!(f, "Invalid color code: {}", msg),
|
|
|
|
|
CalendarError::InvalidOwnerId(msg) => write!(f, "Invalid owner ID: {}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for CalendarError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for Calendar entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type CalendarResult<T> = Result<T, CalendarError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// CALENDAR EVENT ERRORS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Errors that can occur during CalendarEvent entity operations
|
2026-02-06 20:57:00 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum CalendarEventError {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid event summary/title
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidSummary(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid event dates
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidDates(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid recurrence rule
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidRecurrence(String),
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Invalid iCalendar data
|
2026-02-06 20:57:00 +01:00
|
|
|
InvalidICalData(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Display for CalendarEventError {
|
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
|
|
|
match self {
|
|
|
|
|
CalendarEventError::InvalidSummary(msg) => write!(f, "Invalid event summary: {}", msg),
|
|
|
|
|
CalendarEventError::InvalidDates(msg) => write!(f, "Invalid event dates: {}", msg),
|
|
|
|
|
CalendarEventError::InvalidRecurrence(msg) => write!(f, "Invalid recurrence rule: {}", msg),
|
|
|
|
|
CalendarEventError::InvalidICalData(msg) => write!(f, "Invalid iCalendar data: {}", msg),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Error for CalendarEventError {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Type alias for CalendarEvent entity operation results
|
2026-02-06 20:57:00 +01:00
|
|
|
pub type CalendarEventResult<T> = Result<T, CalendarEventError>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// TESTS
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_file_error_display() {
|
|
|
|
|
let err = FileError::InvalidFileName("test.txt".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Invalid file name: test.txt");
|
|
|
|
|
|
|
|
|
|
let err = FileError::ValidationError("size too large".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Validation error: size too large");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_folder_error_display() {
|
|
|
|
|
let err = FolderError::InvalidFolderName("my/folder".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Invalid folder name: my/folder");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_user_error_display() {
|
|
|
|
|
let err = UserError::InvalidUsername("".to_string());
|
2026-02-12 09:41:25 +01:00
|
|
|
assert_eq!(err.to_string(), "Invalid username: ");
|
2026-02-06 20:57:00 +01:00
|
|
|
|
|
|
|
|
let err = UserError::AuthenticationError("invalid credentials".to_string());
|
2026-02-12 09:41:25 +01:00
|
|
|
assert_eq!(err.to_string(), "Authentication error: invalid credentials");
|
2026-02-06 20:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_share_error_display() {
|
|
|
|
|
let err = ShareError::InvalidToken("abc123".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Invalid token: abc123");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_calendar_error_display() {
|
|
|
|
|
let err = CalendarError::InvalidColor("not-a-color".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Invalid color code: not-a-color");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_calendar_event_error_display() {
|
|
|
|
|
let err = CalendarEventError::InvalidDates("end before start".to_string());
|
|
|
|
|
assert_eq!(err.to_string(), "Invalid event dates: end before start");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_errors_implement_error_trait() {
|
|
|
|
|
fn assert_error<E: Error>() {}
|
|
|
|
|
|
|
|
|
|
assert_error::<FileError>();
|
|
|
|
|
assert_error::<FolderError>();
|
|
|
|
|
assert_error::<UserError>();
|
|
|
|
|
assert_error::<ShareError>();
|
|
|
|
|
assert_error::<CalendarError>();
|
|
|
|
|
assert_error::<CalendarEventError>();
|
|
|
|
|
}
|
|
|
|
|
}
|