user_management.domain.exceptions.user package

Exceptions related to User entity validation and business rules.

Each exception represents a specific violation of domain invariants, enabling precise error handling and meaningful feedback during user management operations.

exception user_management.domain.exceptions.user.InvalidCreatedAtError[source]

Bases: InvalidUserError

Raised when created_at timestamp is invalid.

A valid created_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be unrealistically old

Critical for audit trails and compliance (e.g., HIPAA/GDPR).

exception user_management.domain.exceptions.user.InvalidDateOfBirthError[source]

Bases: InvalidUserError

Raised when date of birth is in the future or unrealistically far in the past.

Business rule: date of birth must be:
  • A valid date object

  • Not in the future

  • Not before 1900 (or configurable minimum)

Example violations: born in 2050 or 1800.

exception user_management.domain.exceptions.user.InvalidEmailError[source]

Bases: InvalidUserError

Raised when an email does not conform to RFC-like formatting rules.

Valid emails must:
  • Be a non-empty string

  • Contain exactly one ‘@’

  • Have valid local-part and domain structure

Example invalid values: ‘invalid-email’, ‘user@’, @domain.com

exception user_management.domain.exceptions.user.InvalidNameError[source]

Bases: InvalidUserError

Raised when first_name or last_name contains invalid characters.

Names must:
  • Be non-empty strings

  • Contain only alphabetic characters (A-Z, a-z) and single spaces

  • Not include numbers, symbols, accents, or consecutive spaces

Ensures consistency and compliance in personal data representation.

exception user_management.domain.exceptions.user.InvalidPhoneNumberError[source]

Bases: InvalidUserError

Raised when phone number is provided but not in E.164 format.

Valid format: ‘+’ followed by 1–15 digits (e.g., ‘+1234567890’).

Example invalid values:
  • ‘123-456-7890’ (formatted)

  • ‘1234567890’ (missing +)

  • ‘+12’ (too short)

Aligns with international telephony standards for global systems.

exception user_management.domain.exceptions.user.InvalidUUIDError[source]

Bases: InvalidUserError

Raised when the provided UUID is not a valid UUID instance.

This includes:
  • None

  • Empty string

  • Malformed string (e.g., ‘not-a-uuid’)

  • Wrong type (e.g., int, dict, list)

The User entity requires a valid UUID object for identity integrity and auditability.

exception user_management.domain.exceptions.user.InvalidUpdatedAtError[source]

Bases: InvalidUserError

Raised when updated_at timestamp is invalid.

A valid updated_at must:
  • Be a timezone-aware datetime object

  • Use UTC timezone

  • Not be in the future

  • Not be earlier than created_at

Enforces chronological consistency in user record history.

exception user_management.domain.exceptions.user.InvalidUserError[source]

Bases: DomainError

Base exception raised when a User violates identity or business rules.

Serves as the parent class for all user-related validation errors. Helps enable broad exception handling at higher layers while preserving specificity.

Examples

  • Invalid UUID format

  • Malformed email address

  • Name containing invalid characters

  • Date of birth in the future

exception user_management.domain.exceptions.user.InvalidUserRoleError[source]

Bases: InvalidUserError

Raised when the assigned role is not a valid UserRole enum member.

The system only accepts predefined roles like PATIENT, DOCTOR, NURSE, ADMINISTRATOR.

Prevents unauthorized access levels due to invalid or malformed roles.

exception user_management.domain.exceptions.user.InvalidUserStatusError[source]

Bases: InvalidUserError

Raised when the user status is not a valid UserStatus enum member.

Only ACTIVE, INACTIVE, and LOCKED are allowed.

Ensures account lifecycle state is always consistent and auditable.

Submodules

user_management.domain.exceptions.user.user_exceptions module