Coverage for lice2/api/exceptions.py: 100%
18 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-13 11:11 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-13 11:11 +0000
1"""Define custom exceptions for the API."""
3from __future__ import annotations
6class LiceError(Exception):
7 """Base class for all exceptions in the Lice API."""
10class LicenseNotFoundError(LiceError):
11 """Raised when a license is not found in the database."""
13 def __init__(self, license_name: str) -> None:
14 """Initialize the LicenseNotFoundError exception.
16 Args:
17 license_name: The name of the license that was not found.
18 """
19 self.license_name = license_name
20 super().__init__(f"License '{self.license_name}' is unknown.")
23class LanguageNotFoundError(LiceError):
24 """Raised when a language is not found in the database."""
26 def __init__(self, language_name: str) -> None:
27 """Initialize the LanguageNotFoundError exception.
29 Args:
30 language_name: The name of the language that was not found.
31 """
32 self.language_name = language_name
33 super().__init__(f"Language '{self.language_name}' is unknown.")
36class HeaderNotFoundError(LiceError):
37 """Raised when a header is not found for the supplied license."""
39 def __init__(self, license_name: str) -> None:
40 """Initialize the NoHeaderFoundError exception.
42 Args:
43 license_name: The name of the license without a header.
44 """
45 self.license_name = license_name
46 super().__init__(
47 f"License '{self.license_name}' does not have any headers."
48 )
51class InvalidYearError(LiceError):
52 """Raised when an invalid year is supplied."""
54 def __init__(self, year: str | int) -> None:
55 """Initialize the InvalidYearError exception.
57 Args:
58 year: The year that was not valid.
59 """
60 self.year = year
61 super().__init__(
62 f"Year '{self.year}' is not a valid year (must be 4 digits)."
63 )