diff --git a/archinstall/lib/boot.py b/archinstall/lib/boot.py index 9c772333ec..d72ff3b1c0 100644 --- a/archinstall/lib/boot.py +++ b/archinstall/lib/boot.py @@ -1,5 +1,6 @@ import time from collections.abc import Iterator +from types import TracebackType from .exceptions import SysCallError from .general import SysCommand, SysCommandWorker, locate_binary @@ -47,13 +48,13 @@ def __enter__(self) -> 'Boot': storage['active_boot'] = self return self - def __exit__(self, *args: str, **kwargs: str) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager - if len(args) >= 2 and args[1]: + if exc_type is not None: error( - args[1], + str(exc_value), f'The error above occurred in a temporary boot-up of the installation {self.instance}', ) diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 056e0133e2..66d8ee03dd 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -16,6 +16,7 @@ from pathlib import Path from select import EPOLLHUP, EPOLLIN, epoll from shutil import which +from types import TracebackType from typing import Any, override from .exceptions import RequirementError, SysCallError @@ -170,7 +171,7 @@ def __str__(self) -> str: def __enter__(self) -> 'SysCommandWorker': return self - def __exit__(self, *args: str) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager @@ -186,8 +187,8 @@ def __exit__(self, *args: str) -> None: sys.stdout.write('\n') sys.stdout.flush() - if len(args) >= 2 and args[1]: - debug(args[1]) + if exc_type is not None: + debug(str(exc_value)) if self.exit_code != 0: raise SysCallError( @@ -327,12 +328,12 @@ def __init__( def __enter__(self) -> SysCommandWorker | None: return self.session - def __exit__(self, *args: str, **kwargs: dict[str, Any]) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager - if len(args) >= 2 and args[1]: - error(args[1]) + if exc_type is not None: + error(str(exc_value)) def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes]: if self.session: diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index d5c799ada7..f6a544c1ab 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -124,9 +124,9 @@ def __init__( def __enter__(self) -> 'Installer': return self - def __exit__(self, exc_type: type[BaseException] | None, exc_val, exc_tb: TracebackType | None) -> bool: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> bool | None: if exc_type is not None: - error(exc_val) + error(str(exc_value)) self.sync_log_to_install_medium() @@ -134,7 +134,9 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_val, exc_tb: Traceb # and then reboot, and a identical log file will be found in the ISO medium anyway. Tui.print(str(tr('[!] A log file has been created here: {}').format(logger.path))) Tui.print(tr('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues')) - raise exc_val + + # Return None to propagate the exception + return None if not (missing_steps := self.post_install_check()): msg = f'Installation completed without any errors.\nLog files temporarily available at {logger.directory}.\nYou may reboot when ready.\n' diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index c00ef5806b..e31c361b54 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -4,6 +4,7 @@ from dataclasses import dataclass from pathlib import Path from subprocess import CalledProcessError +from types import TracebackType from archinstall.lib.disk.utils import get_lsblk_info, umount @@ -47,7 +48,7 @@ def __post_init__(self) -> None: def __enter__(self) -> None: self.unlock(self.key_file) - def __exit__(self, *args: str, **kwargs: str) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: if self.auto_unmount: self.lock() diff --git a/archinstall/lib/menu/abstract_menu.py b/archinstall/lib/menu/abstract_menu.py index e35a8ac978..3dfab04630 100644 --- a/archinstall/lib/menu/abstract_menu.py +++ b/archinstall/lib/menu/abstract_menu.py @@ -1,5 +1,6 @@ from __future__ import annotations +from types import TracebackType from typing import Any, Self from archinstall.lib.translationhandler import tr @@ -36,13 +37,15 @@ def __enter__(self, *args: Any, **kwargs: Any) -> Self: self.is_context_mgr = True return self - def __exit__(self, *args: Any, **kwargs: Any) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager # TODO: skip processing when it comes from a planified exit - if len(args) >= 2 and args[1]: - error(args[1]) + if exc_type is not None: + error(str(exc_value)) Tui.print('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues') - raise args[1] + + # Return None to propagate the exception + return None self.sync_all_to_config() diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index 49e538219e..000794eff2 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -49,7 +49,7 @@ def __enter__(self) -> Self: self.start_time = time.time() return self - def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: if self.start_time: time_delta = time.time() - self.start_time signal.alarm(0) diff --git a/archinstall/tui/curses_menu.py b/archinstall/tui/curses_menu.py index 545a553b9b..4f0d437164 100644 --- a/archinstall/tui/curses_menu.py +++ b/archinstall/tui/curses_menu.py @@ -1225,7 +1225,7 @@ def __enter__(self) -> None: tui = self.init() Tui._t = tui - def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, tb: TracebackType | None) -> None: + def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: self.stop() @property diff --git a/pyproject.toml b/pyproject.toml index 5ab3f096b8..5a73af7d26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -225,7 +225,6 @@ ignore = [ "PLW1514", # unspecified-encoding "PLW1641", # eq-without-hash "PLW2901", # redefined-loop-name - "PYI036", # bad-exit-annotation "RUF005", # collection-literal-concatenation "RUF015", # unnecessary-iterable-allocation-for-first-element "RUF039", # unraw-re-pattern