Fix use of kwargs passed up AqtException inheritance tree

This commit is contained in:
Dave Dalcino
2022-08-11 21:41:55 -07:00
parent 0650ac9283
commit c59770bfa2

View File

@@ -18,15 +18,15 @@
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from typing import List from typing import List, Optional
DOCS_CONFIG = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration" DOCS_CONFIG = "https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration"
class AqtException(Exception): class AqtException(Exception):
def __init__(self, *args, **kwargs): def __init__(self, *args, suggested_action: Optional[List[str]] = None, should_show_help: bool = False, **kwargs):
self.suggested_action: List[str] = kwargs.pop("suggested_action", []) self.suggested_action: List[str] = suggested_action or []
self.should_show_help: bool = kwargs.pop("should_show_help", False) self.should_show_help: bool = should_show_help or False
super(AqtException, self).__init__(*args, **kwargs) super(AqtException, self).__init__(*args, **kwargs)
def __format__(self, format_spec) -> str: def __format__(self, format_spec) -> str:
@@ -53,16 +53,19 @@ class ArchiveChecksumError(ArchiveDownloadError):
class ChecksumDownloadFailure(ArchiveDownloadError): class ChecksumDownloadFailure(ArchiveDownloadError):
def __init__(self, *args, **kwargs): def __init__(self, *args, suggested_action: Optional[List[str]] = None, **kwargs):
kwargs["suggested_action"] = kwargs.pop("suggested_action", []).extend( if suggested_action is None:
suggested_action = []
suggested_action.extend(
[ [
"Check your internet connection", "Check your internet connection",
"Consider modifying `requests.max_retries_to_retrieve_hash` in settings.ini", "Consider modifying `requests.max_retries_to_retrieve_hash` in settings.ini",
f"Consider modifying `mirrors.trusted_mirrors` in settings.ini (see {DOCS_CONFIG})", f"Consider modifying `mirrors.trusted_mirrors` in settings.ini (see {DOCS_CONFIG})",
] ]
) )
kwargs["should_show_help"] = True super(ChecksumDownloadFailure, self).__init__(
super(ChecksumDownloadFailure, self).__init__(*args, **kwargs) *args, suggested_action=suggested_action, should_show_help=True, **kwargs
)
class ArchiveConnectionError(AqtException): class ArchiveConnectionError(AqtException):