1# Copyright New York University and the TUF contributors
2# SPDX-License-Identifier: MIT OR Apache-2.0
3
4"""
5Define TUF exceptions used inside the new modern implementation.
6The names chosen for TUF Exception classes should end in 'Error' except where
7there is a good reason not to, and provide that reason in those cases.
8"""
9
10
11#### Repository errors ####
12
13from securesystemslib.exceptions import StorageError # noqa: F401
14
15
16class RepositoryError(Exception):
17 """An error with a repository's state, such as a missing file.
18
19 It covers all exceptions that come from the repository side when
20 looking from the perspective of users of metadata API or ngclient.
21 """
22
23
24class UnsignedMetadataError(RepositoryError):
25 """An error about metadata object with insufficient threshold of
26 signatures.
27 """
28
29
30class BadVersionNumberError(RepositoryError):
31 """An error for metadata that contains an invalid version number."""
32
33
34class EqualVersionNumberError(BadVersionNumberError):
35 """An error for metadata containing a previously verified version number."""
36
37
38class ExpiredMetadataError(RepositoryError):
39 """Indicate that a TUF Metadata file has expired."""
40
41
42class LengthOrHashMismatchError(RepositoryError):
43 """An error while checking the length and hash values of an object."""
44
45
46#### Download Errors ####
47
48
49class DownloadError(Exception):
50 """An error occurred while attempting to download a file."""
51
52
53class DownloadLengthMismatchError(DownloadError):
54 """Indicate that a mismatch of lengths was seen while downloading a file."""
55
56
57class SlowRetrievalError(DownloadError):
58 """Indicate that downloading a file took an unreasonably long time."""
59
60
61class DownloadHTTPError(DownloadError):
62 """
63 Returned by FetcherInterface implementations for HTTP errors.
64
65 Args:
66 message: The HTTP error message
67 status_code: The HTTP status code
68 """
69
70 def __init__(self, message: str, status_code: int):
71 super().__init__(message)
72 self.status_code = status_code