fix: send every refusal as an error event

--romm-firmware, --pack without a platform, an option the list does not
record, a board list the run cannot go on without, a full drive and the
--dest a named platform needs printed and exited on their own: --events
got end and no error. Each now raises Refusal where it is decided, and
refuse_name, --find and the space check stop formatting their own copy.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 21:42:20 +01:00
1 parent 571c4bbfd9
commit 665e2ebb52
13 files changed
+418 -470

No files matched your search

+16 -20
View File
@@ -1,7 +1,6 @@
"""The plan shown before a download: what comes, its size and the space it needs."""
from __future__ import annotations
import sys
from collections.abc import Collection
from pathlib import Path
from typing import TYPE_CHECKING
@@ -15,6 +14,7 @@ from installer.outcome import EVERYTHING_IN_PLACE
from installer.paths import shown_path
from installer.plan_words import _sized
from installer.platforms import OTHER_TITLE, entry_systems, system_title
from installer.refusal import Refusal
from installer.space import space_shortfall
from installer.tally import _bytes, parts_words, tally
from installer.terminal import terminal_size
@@ -249,25 +249,21 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int =
free = shortfall[1]
EVENTS.emit("no_space", platform=plat, folder=str(bios_path), bytes_needed=needed,
bytes_free=free)
EVENTS.emit("error", stage="space", reason="drive_full", platform=plat,
message=f"Not enough space on the drive holding {bios_path}: "
f"{format_size(needed)} needed, {format_size(free)} free.")
print(f"\nNot enough space on the drive holding {bios_path}.", file=sys.stderr)
print(f" Needed: {format_size(needed)}. Free: {format_size(free)}.",
file=sys.stderr)
lines = [f"\nNot enough space on the drive holding {bios_path}.",
f" Needed: {format_size(needed)}. Free: {format_size(free)}."]
if card:
# Its system reads this card alone: another drive, with RetroArch's
# list, was offered for an Onion card.
print(f" Free up {format_size(needed - free)} on the card, then run it again: "
"its system reads its BIOS files there only.", file=sys.stderr)
sys.exit(code)
if not plat:
print(f" Free up {format_size(needed - free)}, or use --dest to install "
"to another drive.", file=sys.stderr)
sys.exit(code)
# --dest alone used to mean RetroArch's list: the platform is named, so
# a Batocera install moved to a USB drive stays Batocera's.
print(f" Free up {format_size(needed - free)}, or install to another drive:\n"
f" {_INVOCATION.command(plat, '<folder on another drive>')}",
file=sys.stderr)
sys.exit(code)
lines.append(f" Free up {format_size(needed - free)} on the card, then run it "
"again: its system reads its BIOS files there only.")
elif not plat:
lines.append(f" Free up {format_size(needed - free)}, or use --dest to install "
"to another drive.")
else:
# --dest alone used to mean RetroArch's list: the platform is named, so
# a Batocera install moved to a USB drive stays Batocera's.
lines.append(f" Free up {format_size(needed - free)}, or install to another "
f"drive:\n {_INVOCATION.command(plat, '<folder on another drive>')}")
raise Refusal("space", "drive_full", plat, *lines, code=code,
message=f"Not enough space on the drive holding {bios_path}: "
f"{format_size(needed)} needed, {format_size(free)} free.")
+2 -10
View File
@@ -2,13 +2,12 @@
from __future__ import annotations
import re
import sys
from pathlib import Path, PurePosixPath
from typing import NoReturn
from installer.embedded import _EMBEDDED_RULES, _NO_FOLDER
from installer.events import EVENTS
from installer.manifest import OTHER_SYSTEMS
from installer.refusal import Refusal
# The platforms that publish a core list per board, install/targets/ in the
# repository: a test holds the two equal. Offline, a platform outside it
@@ -197,14 +196,7 @@ def refuse_name(platform: str, *lines: str) -> NoReturn:
2, as for an option argparse refuses: 1 also means --check found files
to fetch, and a script reading it reran the install on a typo forever.
"""
message = " ".join(line.strip() for line in lines)
if message.startswith("Error: "):
message = message[len("Error: "):]
EVENTS.emit("error", stage="option", reason="unknown", platform=platform,
message=message)
for line in lines:
print(line, file=sys.stderr)
sys.exit(2)
raise Refusal("option", "unknown", platform, *lines, code=2)
# Frontends and systems that keep no BIOS folder of their own: each
+6 -8
View File
@@ -1,12 +1,12 @@
"""RomM: where it reads each platform's firmware, and the list laid out under its library."""
from __future__ import annotations
import sys
from pathlib import Path
from typing import TYPE_CHECKING
from installer.console import detail
from installer.host_fs import _is_dir
from installer.refusal import Refusal
if TYPE_CHECKING:
from installer.run_files import _PlatformPass
@@ -133,14 +133,13 @@ def _check_run_romm(run: _InstallRun) -> None:
return
# Applied or refused, never ignored.
if not any(name == "romm" for name, _path in run.platforms):
print("Error: --romm-firmware applies to RomM, which this run does not "
"install for.", file=sys.stderr)
sys.exit(1)
raise Refusal("option", "not_applicable", "romm",
"Error: --romm-firmware applies to RomM, which this run does not "
"install for.")
try:
parse_romm_firmware(args.romm_firmware)
except ValueError as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
raise Refusal("option", "invalid", "romm", f"Error: {exc}") from None
def _pass_romm_layout(run: _InstallRun, p: _PlatformPass) -> None:
@@ -149,8 +148,7 @@ def _pass_romm_layout(run: _InstallRun, p: _PlatformPass) -> None:
try:
layout = romm_firmware_layout(bios_path, run.args.romm_firmware)
except ValueError as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
raise Refusal("option", "invalid", "romm", f"Error: {exc}") from None
if layout is not None:
p.files, library = romm_relayout(p.files, bios_path, *layout)
if library != bios_path:
+33 -31
View File
@@ -49,7 +49,7 @@ from installer.games import fallback_lines, read_games
from installer.install_record import _RECORD_TAKEN, by_record, drop_recorded, record_menu_words
from installer.invocation import _INVOCATION
from installer.line_menu import MenuContext, _prompt_custom_selection
from installer.lists import fetch_manifest, fetch_targets, local_targets
from installer.lists import ListFailure, fetch_manifest, fetch_targets, load_targets, local_targets, targets_failure_lines
from installer.manifest import GAME_DATA
from installer.narrowing import (
_chosen,
@@ -78,6 +78,7 @@ from installer.plan_words import (
unlisted_saves_words,
)
from installer.platforms import PLATFORM_NAMES, display_name, system_title
from installer.refusal import Refusal
from installer.tally import (
_bytes,
_left_out_lines,
@@ -174,13 +175,10 @@ def _found_files(args: argparse.Namespace, plat: str,
*(f" {match['dest']} {match.get('sha1', '')}" for match in matches)],
}.get(result)
if lines is not None:
EVENTS.emit("error", stage="option", reason="unknown", platform=plat,
message=lines[0][len("Error: "):])
for line in lines:
print(line, file=sys.stderr)
# 4: the hash was read and the list holds no one file for it, neither
# a failure (1) nor an option refused (2).
sys.exit(4)
raise Refusal("option", "unknown", plat, *lines, code=4,
message=lines[0][len("Error: "):])
for match in matches:
print(f" {value} is {match['dest']}")
return matches, []
@@ -258,10 +256,10 @@ def _pass_files(run: _InstallRun, plat_name: str, bios_path: Path) -> _PlatformP
p = _PlatformPass(plat_name, bios_path, manifest)
if run.args.source == "truth":
if manifest.get("truth_files") is None:
print(f"Error: the {plat_name} file list does not say what the emulator "
"profiles prove is read, which --source truth needs.", file=sys.stderr)
print(_older_list_advice(plat_name), file=sys.stderr)
sys.exit(1)
raise Refusal("option", "not_recorded", plat_name,
f"Error: the {plat_name} file list does not say what the emulator "
"profiles prove is read, which --source truth needs.",
_older_list_advice(plat_name))
before = len(p.files)
p.files, p.omitted_files = truth_lists(manifest, p.files, p.omitted_files)
detail(f" What the emulator profiles prove is read: {before} to "
@@ -322,10 +320,9 @@ def _pass_options(run: _InstallRun, p: _PlatformPass) -> bool:
if args.no_game_data and not p.manifest.get("categorized"):
# Without the field nothing is marked, and the run would
# install the game data it was asked to leave out.
print(f"Error: the {plat_name} file list records no file category, "
"which --no-game-data needs.", file=sys.stderr)
print(_older_list_advice(plat_name), file=sys.stderr)
sys.exit(1)
raise Refusal("option", "not_recorded", plat_name,
f"Error: the {plat_name} file list records no file category, "
"which --no-game-data needs.", _older_list_advice(plat_name))
if args.declared_only:
before = len(p.files)
@@ -334,9 +331,7 @@ def _pass_options(run: _InstallRun, p: _PlatformPass) -> bool:
"(--declared-only)")
if args.list_targets:
targets = fetch_targets(plat_name)
if targets is None:
sys.exit(1)
targets = needed_targets(plat_name)
if not targets:
print(f" No targets available for {plat_name}")
else:
@@ -390,13 +385,23 @@ def _pass_target(run: _InstallRun, p: _PlatformPass) -> None:
_pass_target_cores(run, p, target)
def needed_targets(plat: str) -> dict:
"""The board list a run cannot go on without, its failure the run's refusal."""
try:
return load_targets(plat)
except ListFailure as stopped:
# A list the run would carry on without stops this one all the same:
# it said why on stderr and ended with code 1, no error event sent.
problem = stopped.problem
raise Refusal("targets", problem.code, problem.plat,
*targets_failure_lines(problem), code=problem.fatal or 1) from None
def _pass_target_cores(run: _InstallRun, p: _PlatformPass, target: str) -> None:
"""The files narrowed to the cores the board's list names."""
targets = run.target_lists.get(p.plat_name)
if targets is None:
targets = fetch_targets(p.plat_name)
if targets is None:
sys.exit(1)
targets = needed_targets(p.plat_name)
target_info = targets.get(target)
if target_info is None:
# Carrying on would install every file, which is the opposite
@@ -433,13 +438,10 @@ def _pass_installed_cores(run: _InstallRun, p: _PlatformPass) -> None:
if not args.installed_cores:
return
if "system_cores" not in manifest:
print(
f"Error: the {plat_name} file list does not say which cores "
"read which systems, which --installed-cores needs.",
file=sys.stderr,
)
print(_older_list_advice(plat_name), file=sys.stderr)
sys.exit(1)
raise Refusal("option", "not_recorded", plat_name,
f"Error: the {plat_name} file list does not say which cores "
"read which systems, which --installed-cores needs.",
_older_list_advice(plat_name))
before = len(p.files)
info_dests = _unprofiled_cores_firmware(
plat_name, bios_path, manifest, found_cores,
@@ -697,10 +699,10 @@ def _pass_narrow(run: _InstallRun, p: _PlatformPass) -> None:
detail(f" Narrowed {before} to {len(p.files)} files")
if args.one_per_slot:
if not p.manifest.get("slot_fields"):
print(f"Error: the {plat_name} file list does not say which files a "
"slot holds, which --one-per-slot needs.", file=sys.stderr)
print(_older_list_advice(plat_name), file=sys.stderr)
sys.exit(1)
raise Refusal("option", "not_recorded", plat_name,
f"Error: the {plat_name} file list does not say which files a "
"slot holds, which --one-per-slot needs.",
_older_list_advice(plat_name))
before = len(p.files)
p.files, p.omitted_files = one_per_slot(p.files, p.omitted_files, p.slot_reach)
detail(f" One BIOS per console and region: {before} to {len(p.files)} files")
+25 -41
View File
@@ -26,12 +26,13 @@ from installer.line_folder import (
ask_platform_folder,
share_words,
)
from installer.lists import ListFailure, fetch_targets, load_targets
from installer.lists import ListFailure, load_targets
from installer.offline import LOCAL
from installer.pack import pack_path
from installer.pack_source import pack_name_platforms
from installer.platforms import AVAILABLE_PLATFORMS, _NO_BIOS_FOLDER, display_name, normalize_platform
from installer.run_files import _output_kind
from installer.refusal import Refusal
from installer.run_files import _output_kind, needed_targets
from installer.safe_replace import KEPT
from installer.setups import PORTABLE_ONLY, _default_dest, _line_setups, drive_example, found_setups
from installer.standalone import _install_standalone_folders
@@ -145,9 +146,9 @@ def _start_install(args: argparse.Namespace, real_stdout: TextIO) -> _InstallRun
if args.platform is None:
spelled = pack_name_platforms(Path(os.path.expanduser(str(args.pack))).name)
if len(spelled) != 1:
print("Error: name the platform the pack is for with --platform.",
file=sys.stderr)
sys.exit(2)
raise Refusal("pack", "no_platform", "",
"Error: name the platform the pack is for with --platform.",
code=2)
args.platform = spelled[0]
return _InstallRun(args, term, os_type, interactive, listing, packing)
@@ -187,9 +188,6 @@ def _named_by_list_only(run: _InstallRun) -> NoReturn:
else "the file list")
message = (f"No supported platform detected: {display_name(args.platform)} was "
f"not found here, and {source} does not say where it goes")
EVENTS.emit("error", stage="detect", reason="not_found", platform=args.platform,
message=message)
print(f" {message}.", file=sys.stderr)
hint = Invocation()
hint.os_type, hint.options = run.os_type, _INVOCATION.options
example = _default_dest(run.os_type, args.platform)
@@ -197,10 +195,11 @@ def _named_by_list_only(run: _InstallRun) -> NoReturn:
# example stopped at a question.
answered = "".join(f" {flag}" for flag, on in (
("--yes", args.yes), ("--no-input", args.no_input)) if on)
print(" Name its folder with --dest, for example:\n "
+ hint.command(args.platform, example if example is not None
else "<its BIOS folder>") + answered, file=sys.stderr)
sys.exit(1)
raise Refusal("detect", "not_found", args.platform, f" {message}.",
" Name its folder with --dest, for example:\n "
+ hint.command(args.platform, example if example is not None
else "<its BIOS folder>") + answered,
message=message)
def _named_setup_default(run: _InstallRun) -> list[tuple[str, Path]]:
@@ -212,42 +211,32 @@ def _named_setup_default(run: _InstallRun) -> list[tuple[str, Path]]:
if args.platform in PORTABLE_ONLY:
# A portable emulator reads the folder beside its executable:
# any default would be a folder it never opens.
EVENTS.emit("error", stage="detect", reason="not_found", platform=args.platform,
message=f"Platform '{args.platform}' not found. "
f"{PORTABLE_ONLY[args.platform]}")
print(
raise Refusal(
"detect", "not_found", args.platform,
f" Platform '{args.platform}' not found. {PORTABLE_ONLY[args.platform]} "
f"Name it with --dest, for example: --platform {args.platform} "
f"--dest '<BizHawk folder>{os.sep}Firmware'",
file=sys.stderr,
)
sys.exit(1)
message=f"Platform '{args.platform}' not found. {PORTABLE_ONLY[args.platform]}")
if args.platform in _SHARE_FOLDERS:
# Its own folder exists on the Batocera machine alone, which
# detection would have found: here /userdata/bios was taken, and
# the run ended on "Cannot create" with no event saying why.
message = (f"Platform '{args.platform}' not found here. "
f"{share_words(args.platform)}")
EVENTS.emit("error", stage="detect", reason="not_found", platform=args.platform,
message=message)
example = drive_example(run.os_type, "SHARE", "bios", args.platform)
print(f" {message} Name it with --dest, for example: --platform "
f"{args.platform} --dest {example}", file=sys.stderr)
sys.exit(1)
raise Refusal("detect", "not_found", args.platform,
f" {message} Name it with --dest, for example: --platform "
f"{args.platform} --dest {example}", message=message)
default_dest = _default_dest(run.os_type, args.platform)
if default_dest is None:
where = ("where this user can look, and its default folder may not be "
"the one it reads" if _default_set_aside(run.os_type, args.platform)
else "and no folder on this system is one it reads")
message = f"Platform '{args.platform}' not found {where}"
EVENTS.emit("error", stage="detect", reason="not_found",
platform=args.platform, message=message)
print(
f" {message}. Name it with --dest, for example: "
f"--platform {args.platform} --dest <its BIOS folder>",
file=sys.stderr,
)
sys.exit(1)
raise Refusal("detect", "not_found", args.platform,
f" {message}. Name it with --dest, for example: "
f"--platform {args.platform} --dest <its BIOS folder>",
message=message)
print(
f" Platform '{args.platform}' not detected, "
f"using default path: {default_dest}"
@@ -446,9 +435,7 @@ def _check_run_target(run: _InstallRun) -> None:
drop_recorded(args, plat, "--target", "the board list does not name it")
if args.target:
for plat_name, _bios_path in platforms:
targets = fetch_targets(plat_name)
if targets is None:
sys.exit(1)
targets = needed_targets(plat_name)
run.target_lists[plat_name] = targets
if args.target not in targets:
_unknown_target(args.target, plat_name, targets, *(
@@ -472,12 +459,9 @@ def _check_run_cores(run: _InstallRun) -> None:
drop_recorded(args, plat_name, "--installed-cores",
f"{plat_name} ships its cores with the system")
elif args.installed_cores:
print(
f"Error: {plat_name} ships its cores with the system. "
f"--installed-cores applies to {', '.join(CORE_PLATFORMS)}",
file=sys.stderr,
)
sys.exit(1)
raise Refusal("option", "not_applicable", plat_name,
f"Error: {plat_name} ships its cores with the system. "
f"--installed-cores applies to {', '.join(CORE_PLATFORMS)}")
if args.installed_cores and not run.cores_found[(plat_name, bios_path)]:
if by_record(args):
drop_recorded(args, plat_name, "--installed-cores", "no core is installed")