A small batch of fixes (#81)

* log_analyser: Use a set for notes

* Use sys.exc_info() instead of sys.exception()

sys.exception() only exists since python 3.11

* Create data dir if it doesn't exist
This commit is contained in:
TSRBerry 2024-01-06 15:33:01 +01:00 committed by GitHub
parent caa5cf55ed
commit 03e4fd3541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 43 deletions

View file

@ -19,8 +19,6 @@ sys.path.append(state_dir)
import config import config
# TODO: check __name__ for __main__ nerd
script_name = os.path.basename(__file__).split(".")[0] script_name = os.path.basename(__file__).split(".")[0]
log_file_name = f"{script_name}.log" log_file_name = f"{script_name}.log"
@ -61,6 +59,9 @@ wanted_jsons = [
"data/disabled_ids.json", "data/disabled_ids.json",
] ]
if not os.path.exists(os.path.join(state_dir, "data")):
os.makedirs(os.path.join(state_dir, "data"))
for wanted_json_idx in range(len(wanted_jsons)): for wanted_json_idx in range(len(wanted_jsons)):
wanted_jsons[wanted_json_idx] = os.path.join( wanted_jsons[wanted_json_idx] = os.path.join(
state_dir, wanted_jsons[wanted_json_idx] state_dir, wanted_jsons[wanted_json_idx]
@ -142,7 +143,7 @@ async def on_command(ctx):
async def on_error(event: str, *args, **kwargs): async def on_error(event: str, *args, **kwargs):
log.exception(f"Error on {event}:") log.exception(f"Error on {event}:")
exception = sys.exception() exception = sys.exc_info()[1]
is_report_allowed = any( is_report_allowed = any(
[ [
not isinstance(exception, x) not isinstance(exception, x)
@ -270,15 +271,6 @@ async def on_message(message):
await bot.invoke(ctx) await bot.invoke(ctx)
if not os.path.exists("data"):
os.makedirs("data")
for wanted_json in wanted_jsons:
if not os.path.exists(wanted_json):
with open(wanted_json, "w") as f:
f.write("{}")
async def main(): async def main():
async with bot: async with bot:
if len(config.guild_whitelist) == 1: if len(config.guild_whitelist) == 1:

View file

@ -33,7 +33,7 @@ class LogAnalyser:
_emu_info: dict[str, Optional[str]] _emu_info: dict[str, Optional[str]]
_game_info: dict[str, Optional[str]] _game_info: dict[str, Optional[str]]
_settings: dict[str, Optional[str]] _settings: dict[str, Optional[str]]
_notes: list[str] _notes: Union[set[str], list[str]]
@staticmethod @staticmethod
def is_homebrew(log_file: str) -> bool: def is_homebrew(log_file: str) -> bool:
@ -178,7 +178,7 @@ class LogAnalyser:
"aspect_ratio": "Unknown", "aspect_ratio": "Unknown",
"texture_recompression": "Unknown", "texture_recompression": "Unknown",
} }
self._notes = [] self._notes = set()
self._log_errors = [] self._log_errors = []
def __get_errors(self): def __get_errors(self):
@ -408,10 +408,10 @@ class LogAnalyser:
# Hid Configure lines can appear multiple times, so converting to dict keys removes duplicate entries, # Hid Configure lines can appear multiple times, so converting to dict keys removes duplicate entries,
# also maintains the list order # also maintains the list order
input_status = list(dict.fromkeys(input_status)) input_status = list(dict.fromkeys(input_status))
self._notes.append("\n".join(input_status)) self._notes.add("\n".join(input_status))
# If emulator crashes on startup without game load, there is no need to show controller notification at all # If emulator crashes on startup without game load, there is no need to show controller notification at all
elif self._game_info["game_name"] != "Unknown": elif self._game_info["game_name"] != "Unknown":
self._notes.append("⚠️ No controller information found") self._notes.add("⚠️ No controller information found")
def __get_os_notes(self): def __get_os_notes(self):
if ( if (
@ -419,11 +419,11 @@ class LogAnalyser:
and self._settings["graphics_backend"] != "Vulkan" and self._settings["graphics_backend"] != "Vulkan"
): ):
if "Intel" in self._hardware_info["gpu"]: if "Intel" in self._hardware_info["gpu"]:
self._notes.append( self._notes.add(
"**⚠️ Intel iGPU users should consider using Vulkan graphics backend**" "**⚠️ Intel iGPU users should consider using Vulkan graphics backend**"
) )
if "AMD" in self._hardware_info["gpu"]: if "AMD" in self._hardware_info["gpu"]:
self._notes.append( self._notes.add(
"**⚠️ AMD GPU users should consider using Vulkan graphics backend**" "**⚠️ AMD GPU users should consider using Vulkan graphics backend**"
) )
@ -436,7 +436,7 @@ class LogAnalyser:
) )
if "Debug" in user_logs: if "Debug" in user_logs:
self._notes.append( self._notes.add(
"⚠️ **Debug logs enabled will have a negative impact on performance**" "⚠️ **Debug logs enabled will have a negative impact on performance**"
) )
@ -447,47 +447,47 @@ class LogAnalyser:
else: else:
log_string = "✅ Default logs enabled" log_string = "✅ Default logs enabled"
self._notes.append(log_string) self._notes.add(log_string)
def __get_settings_notes(self): def __get_settings_notes(self):
if self._settings["audio_backend"] == "Dummy": if self._settings["audio_backend"] == "Dummy":
self._notes.append( self._notes.add(
"⚠️ Dummy audio backend, consider changing to SDL2 or OpenAL" "⚠️ Dummy audio backend, consider changing to SDL2 or OpenAL"
) )
if self._settings["pptc"] == "Disabled": if self._settings["pptc"] == "Disabled":
self._notes.append("🔴 **PPTC cache should be enabled**") self._notes.add("🔴 **PPTC cache should be enabled**")
if self._settings["shader_cache"] == "Disabled": if self._settings["shader_cache"] == "Disabled":
self._notes.append("🔴 **Shader cache should be enabled**") self._notes.add("🔴 **Shader cache should be enabled**")
if self._settings["expand_ram"] == "True": if self._settings["expand_ram"] == "True":
self._notes.append( self._notes.add(
"⚠️ `Use alternative memory layout` should only be enabled for 4K mods" "⚠️ `Use alternative memory layout` should only be enabled for 4K mods"
) )
if self._settings["memory_manager"] == "SoftwarePageTable": if self._settings["memory_manager"] == "SoftwarePageTable":
self._notes.append( self._notes.add(
"🔴 **`Software` setting in Memory Manager Mode will give slower performance than the default setting of `Host unchecked`**" "🔴 **`Software` setting in Memory Manager Mode will give slower performance than the default setting of `Host unchecked`**"
) )
if self._settings["ignore_missing_services"] == "True": if self._settings["ignore_missing_services"] == "True":
self._notes.append( self._notes.add(
"⚠️ `Ignore Missing Services` being enabled can cause instability" "⚠️ `Ignore Missing Services` being enabled can cause instability"
) )
if self._settings["vsync"] == "Disabled": if self._settings["vsync"] == "Disabled":
self._notes.append( self._notes.add(
"⚠️ V-Sync disabled can cause instability like games running faster than intended or longer load times" "⚠️ V-Sync disabled can cause instability like games running faster than intended or longer load times"
) )
if self._settings["fs_integrity"] == "Disabled": if self._settings["fs_integrity"] == "Disabled":
self._notes.append( self._notes.add(
"⚠️ Disabling file integrity checks may cause corrupted dumps to not be detected" "⚠️ Disabling file integrity checks may cause corrupted dumps to not be detected"
) )
if self._settings["backend_threading"] == "Off": if self._settings["backend_threading"] == "Off":
self._notes.append( self._notes.add(
"🔴 **Graphics Backend Multithreading should be set to `Auto`**" "🔴 **Graphics Backend Multithreading should be set to `Auto`**"
) )
@ -507,37 +507,37 @@ class LogAnalyser:
for common_error in self.get_common_errors(): for common_error in self.get_common_errors():
match common_error: match common_error:
case CommonError.SHADER_CACHE_COLLISION: case CommonError.SHADER_CACHE_COLLISION:
self._notes.append( self._notes.add(
"⚠️ Cache collision detected. Investigate possible shader cache issues" "⚠️ Cache collision detected. Investigate possible shader cache issues"
) )
case CommonError.SHADER_CACHE_CORRUPTION: case CommonError.SHADER_CACHE_CORRUPTION:
self._notes.append( self._notes.add(
"⚠️ Cache corruption detected. Investigate possible shader cache issues" "⚠️ Cache corruption detected. Investigate possible shader cache issues"
) )
case CommonError.DUMP_HASH: case CommonError.DUMP_HASH:
self._notes.append( self._notes.add(
"⚠️ Dump error detected. Investigate possible bad game/firmware dump issues" "⚠️ Dump error detected. Investigate possible bad game/firmware dump issues"
) )
case CommonError.UPDATE_KEYS: case CommonError.UPDATE_KEYS:
self._notes.append( self._notes.add(
"⚠️ Keys or firmware out of date, consider updating them" "⚠️ Keys or firmware out of date, consider updating them"
) )
case CommonError.FILE_PERMISSIONS: case CommonError.FILE_PERMISSIONS:
self._notes.append( self._notes.add(
"⚠️ File permission error. Consider deleting save directory and allowing Ryujinx to make a new one" "⚠️ File permission error. Consider deleting save directory and allowing Ryujinx to make a new one"
) )
case CommonError.FILE_NOT_FOUND: case CommonError.FILE_NOT_FOUND:
self._notes.append( self._notes.add(
"⚠️ Save not found error. Consider starting game without a save file or using a new save file⚠️ Save not found error. Consider starting game without a save file or using a new save file" "⚠️ Save not found error. Consider starting game without a save file or using a new save file"
) )
case CommonError.MISSING_SERVICES: case CommonError.MISSING_SERVICES:
if self._settings["ignore_missing_services"] == "False": if self._settings["ignore_missing_services"] == "False":
self._notes.append( self._notes.add(
"⚠️ Consider enabling `Ignore Missing Services` in Ryujinx settings" "⚠️ Consider enabling `Ignore Missing Services` in Ryujinx settings"
) )
case CommonError.VULKAN_OUT_OF_MEMORY: case CommonError.VULKAN_OUT_OF_MEMORY:
if self._settings["texture_recompression"] == "Disabled": if self._settings["texture_recompression"] == "Disabled":
self._notes.append( self._notes.add(
"⚠️ Consider enabling `Texture Recompression` in Ryujinx settings" "⚠️ Consider enabling `Texture Recompression` in Ryujinx settings"
) )
case _: case _:
@ -547,10 +547,10 @@ class LogAnalyser:
latest_timestamp = re.findall(timestamp_regex, self._log_text)[-1] latest_timestamp = re.findall(timestamp_regex, self._log_text)[-1]
if latest_timestamp: if latest_timestamp:
timestamp_message = f" Time elapsed: `{latest_timestamp}`" timestamp_message = f" Time elapsed: `{latest_timestamp}`"
self._notes.append(timestamp_message) self._notes.add(timestamp_message)
if self.is_default_user_profile(): if self.is_default_user_profile():
self._notes.append( self._notes.add(
"⚠️ Default user profile in use, consider creating a custom one." "⚠️ Default user profile in use, consider creating a custom one."
) )
@ -562,11 +562,11 @@ class LogAnalyser:
and self._game_info["game_name"] != "Unknown" and self._game_info["game_name"] != "Unknown"
): ):
firmware_warning = f"**❌ Nintendo Switch firmware not found**" firmware_warning = f"**❌ Nintendo Switch firmware not found**"
self._notes.append(firmware_warning) self._notes.add(firmware_warning)
self.__get_settings_notes() self.__get_settings_notes()
if self.get_ryujinx_version() == RyujinxVersion.CUSTOM: if self.get_ryujinx_version() == RyujinxVersion.CUSTOM:
self._notes.append("**⚠️ Custom builds are not officially supported**") self._notes.add("**⚠️ Custom builds are not officially supported**")
def get_ryujinx_version(self): def get_ryujinx_version(self):
mainline_version = re.compile(r"^\d\.\d\.\d+$") mainline_version = re.compile(r"^\d\.\d\.\d+$")
@ -655,7 +655,7 @@ class LogAnalyser:
self._game_info["cheats"] = "\n".join(limit_cheats) self._game_info["cheats"] = "\n".join(limit_cheats)
if is_channel_allowed and self.get_ryujinx_version() == RyujinxVersion.PR: if is_channel_allowed and self.get_ryujinx_version() == RyujinxVersion.PR:
self._notes.append( self._notes.add(
f"**⚠️ PR build logs should be posted in <#{pr_channel}> if reporting bugs or tests**" f"**⚠️ PR build logs should be posted in <#{pr_channel}> if reporting bugs or tests**"
) )