-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patherrors.py
47 lines (32 loc) · 1.42 KB
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from typing import Any
class AssetOverwriteError(Exception):
"""Raised when an asset would be overwritten during download."""
def __init__(self, hrefs: list[str]) -> None:
super().__init__(
f"assets have the same file names and would overwrite each other: {hrefs}"
)
class DownloadWarning(Warning):
"""A warning for when something couldn't be downloaded.
Used when we don't want to cancel all downloads, but still inform the user
about the problem.
"""
class ConfigError(Exception):
"""Raised if the configuration is not valid."""
class ContentTypeError(Exception):
"""The expected content type does not match the actual content type."""
def __init__(self, actual: str, expected: str, *args: Any, **kwargs: Any) -> None:
super().__init__(
f"the actual content type does not match the expected: actual={actual}, "
f"expected={expected}",
*args,
**kwargs,
)
class DownloadError(Exception):
"""A collection of exceptions encountered while downloading."""
exceptions: list[Exception]
def __init__(self, exceptions: list[Exception], *args: Any, **kwargs: Any) -> None:
self.exceptions = exceptions
messages = list()
for exception in exceptions:
messages.append(f"{type(exception).__name__}: {exception}")
super().__init__("\n".join(messages), *args, **kwargs)