"""Defines a few application-specific exceptions for Pythonic code.""" class UmbrellaNotFoundError(Exception): """For when an umbrella with required serial is not found in database.""" def __init__(self, serial): self.serial = serial self.message = f"No umbrella {serial} found." super().__init__(self.message) class UmbrellaStatusError(Exception): """For when the umbrella to be lent is not available, or when an umbrella to be returned has never been taken away. Most likely duplicate or erroneous answer sheets submitted by user. """ pass class UmbrellaValueError(Exception): """For when an admin enters an invalid value when modifying the database.""" def __init__(self, field: str): self.field = field self.message = f"Invalid field: {field}." super().__init__(self.message) class TenantIdentityError(Exception): """For when a tenant attempts to return an umbrella that's borrowed by another tenant.""" def __init__(self, expected, got): self.expected = expected self.got = got self.message = f"Umbrella is borrowed by {expected} and {got} cannot return it." super().__init__(self.message) class UsernameTakenError(Exception): """For when a username to be registered with is already taken.""" def __init__(self, username: str): self.username = username self.message = f"Username {username} is already taken." super().__init__(self.message)