mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 12:28:51 -06:00
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:
1 parent
ced68a9135
commit
eba627aa89
20 files changed
+542
-402
No files matched your search
@@ -0,0 +1,36 @@
|
||||
"""A refusal that ends the run, raised where it is decided and reported once by the command."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from installer.events import EVENTS
|
||||
|
||||
|
||||
class Refusal(SystemExit):
|
||||
"""The run refused, with the error event a script reads and the lines a
|
||||
person reads. Each site printed its lines and chose on its own whether
|
||||
--events got the reason, and several did not: a script learned code 1
|
||||
and nothing else. message is the event's, by default the lines joined
|
||||
without their leading "Error: "."""
|
||||
|
||||
def __init__(self, stage: str, reason: str, platform: str, *lines: str,
|
||||
code: int = 1, message: str | None = None) -> None:
|
||||
super().__init__(code)
|
||||
self.stage, self.reason, self.platform = stage, reason, platform
|
||||
self.lines = lines
|
||||
if message is None:
|
||||
message = " ".join(line.strip() for line in lines)
|
||||
if message.startswith("Error: "):
|
||||
message = message[len("Error: "):]
|
||||
self.message = message
|
||||
self.reported = False
|
||||
|
||||
def report(self) -> None:
|
||||
"""The error event, then the lines on stderr, once."""
|
||||
if self.reported:
|
||||
return
|
||||
self.reported = True
|
||||
EVENTS.emit("error", stage=self.stage, reason=self.reason, platform=self.platform,
|
||||
message=self.message)
|
||||
for line in self.lines:
|
||||
print(line, file=sys.stderr)
|
||||
Reference in new issue
Block a user