refactor: one refusal path to stderr and events

Library functions printed their refusal and exited, each deciding on its
own whether --events got an error event. --cores-dir, --installed-cores
with no core, a list without system_cores or standalone_builds, a pack
that cannot be used, a board list a run needs and --dest alone beside
two setups ended on code 1 with no reason in the stream.

They now raise Refusal (installer/refusal.py), carrying the stage, the
reason, the platform, the lines and the code. The install, an action
framed by events and main report it once: the error event, then the
same lines on stderr, so the text and exit codes stay as they were.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:46 +01:00
1 parent ced68a9135
commit eba627aa89
20 files changed
+542 -402

No files matched your search

+10 -1
View File
@@ -30,6 +30,7 @@ from installer.narrowing import FIND_KINDS
from installer.network import _RAW_ERRORS, install_bounded_opener
from installer.offline import LOCAL, OFFLINE_FLAG_VALUE, offline_named
from installer.platforms import AVAILABLE_PLATFORMS, TARGET_PLATFORMS, _name_key, display_name, refuse_name
from installer.refusal import Refusal
from installer.regions import resolve_regions
from installer.remote import remote_from_env, remote_in_use
from installer.removal import run_backups, run_delete_backup, run_removal
@@ -311,7 +312,13 @@ def main() -> None:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
with remote_in_use(remote):
_main_run()
try:
_main_run()
except Refusal as refusal:
# Raised outside an install, which reports its own: the full
# screen's start, an action and the sources opened before it.
refusal.report()
raise
def _main_run() -> None:
@@ -438,6 +445,8 @@ def _run_action(args: argparse.Namespace,
try:
code = action(args)
except SystemExit as exc:
if isinstance(exc, Refusal):
exc.report()
EVENTS.emit("end", code=_event_exit_code(exc.code))
raise
except KeyboardInterrupt: