Retire "PATH_NOT_SET", "NOT_EXECUTABLE" and "NO_BIOS" in error codes in favor of exceptions.

Only NO_BIOS gets its own exception class, as its hte only one raised in more than one place. This way we can avoid repeating the message.

                elif error == "NO_BIOS":
            message_text = _("A bios file is required to run this game")
This commit is contained in:
Daniel Johnson 2023-12-27 18:07:05 -05:00
parent 284cb0282d
commit d5de4465f4
7 changed files with 21 additions and 19 deletions

View file

@ -21,6 +21,13 @@ class GameConfigError(MisconfigurationError):
running properly."""
class MissingBiosError(GameConfigError):
"""Throw this error when the game requires a BIOS, but none is configured."""
def __init__(self, message=None, *args, **kwarg):
super().__init__(message or _("A bios file is required to run this game"), *args, **kwarg)
class AuthenticationError(LutrisError):
"""Raised when authentication to a service fails"""

View file

@ -275,19 +275,12 @@ class Game(GObject.Object):
error = gameplay_info["error"]
if error == "CUSTOM":
message_text = gameplay_info["text"]
elif error == "NO_BIOS":
message_text = _("A bios file is required to run this game")
elif error == "FILE_NOT_FOUND":
filename = gameplay_info["file"]
if filename:
message_text = _("The file {} could not be found").format(filename)
else:
message_text = _("This game has no executable set. The install process didn't finish properly.")
elif error == "NOT_EXECUTABLE":
file = gameplay_info["file"]
message_text = _("The file %s is not executable") % file
elif error == "PATH_NOT_SET":
message_text = _("The path '%s' is not set. please set it in the options.") % gameplay_info["path"]
else:
message_text = _("Unhandled error: %s") % gameplay_info["error"]
return GameConfigError(message_text)

View file

@ -3,6 +3,7 @@ import os.path
from gettext import gettext as _
from lutris.config import LutrisConfig
from lutris.exceptions import MissingBiosError
from lutris.runners.runner import Runner
from lutris.util import display, extract, system
@ -132,7 +133,7 @@ class atari800(Runner):
bios_path = self.runner_config.get("bios_path")
if not system.path_exists(bios_path):
return {"error": "NO_BIOS"}
raise MissingBiosError()
good_bios = self.find_good_bioses(bios_path)
for bios, filename in good_bios.items():
arguments.append("-%s" % bios)

View file

@ -5,6 +5,7 @@ from gettext import gettext as _
# Lutris Modules
from lutris.config import LutrisConfig
from lutris.exceptions import MissingBiosError
from lutris.runners.runner import Runner
from lutris.util import system
@ -175,7 +176,7 @@ class hatari(Runner):
params.append("--tos")
params.append(self.runner_config["bios_file"])
else:
return {"error": "NO_BIOS"}
raise MissingBiosError()
diska = self.game_config.get("disk-a")
if not system.path_exists(diska):
return {"error": "FILE_NOT_FOUND", "file": diska}

View file

@ -2,6 +2,7 @@
import os
from gettext import gettext as _
from lutris.exceptions import MissingBiosError
# Lutris Modules
from lutris.runners.runner import Runner
from lutris.util import system
@ -77,7 +78,7 @@ class jzintv(Runner):
arguments.append("--execimg=%s/exec.bin" % bios_path)
arguments.append("--gromimg=%s/grom.bin" % bios_path)
else:
return {"error": "NO_BIOS"}
raise MissingBiosError()
rom_path = self.game_config.get("main_file") or ""
if not system.path_exists(rom_path):
return {"error": "FILE_NOT_FOUND", "file": rom_path}

View file

@ -156,16 +156,14 @@ class linux(Runner):
"""Run native game."""
launch_info = {}
if not self.game_exe or not system.path_exists(self.game_exe):
return {"error": "FILE_NOT_FOUND", "file": self.game_exe}
exe = self.game_exe
if not exe or not system.path_exists(exe):
return {"error": "FILE_NOT_FOUND", "file": exe}
# Quit if the file is not executable
mode = os.stat(self.game_exe).st_mode
mode = os.stat(exe).st_mode
if not mode & stat.S_IXUSR:
return {"error": "NOT_EXECUTABLE", "file": self.game_exe}
if not system.path_exists(self.game_exe):
return {"error": "FILE_NOT_FOUND", "file": self.game_exe}
raise GameConfigError(_("The file %s is not executable") % exe)
ld_preload = self.game_config.get("ld_preload")
if ld_preload:
@ -175,7 +173,7 @@ class linux(Runner):
if ld_library_path:
launch_info["ld_library_path"] = os.path.expanduser(ld_library_path)
command = [self.get_relative_exe(self.game_exe, self.working_dir)]
command = [self.get_relative_exe(exe, self.working_dir)]
args = self.game_config.get("args") or ""
for arg in split_arguments(args):

View file

@ -3,6 +3,7 @@ import os
from gettext import gettext as _
from lutris import runtime, settings
from lutris.exceptions import GameConfigError
from lutris.runners.runner import Runner
from lutris.util import system
from lutris.util.jobs import AsyncCall
@ -328,7 +329,7 @@ class mame(Runner): # pylint: disable=invalid-name
rompath = self.runner_config.get("rompath")
rom = os.path.basename(self.game_config.get("main_file"))
if not rompath:
return {'error': 'PATH_NOT_SET', 'path': 'rompath'}
raise GameConfigError(_("The path '%s' is not set. please set it in the options.") % 'rompath')
command += ["-rompath", rompath, rom]
if self.game_config.get("autoboot_command"):