Shows error snippet on empty log (#6)

* Error snippet shown on empty log
- Shader cache corruption warning

* Loop to get missing info in log

* Error search handles multiple terms
- Minor spelling correction for resolution value
- User settings visible on empty log
This commit is contained in:
Mark Araujo 2021-06-18 19:29:31 +01:00 committed by Mary
parent d1c536e792
commit da9ea20a9d

View file

@ -66,51 +66,71 @@ class LogFileReader(Cog):
log_file = re.search(log_file_header_regex, log_file).group(0) log_file = re.search(log_file_header_regex, log_file).group(0)
def get_hardware_info(log_file=log_file): def get_hardware_info(log_file=log_file):
try: for setting in self.embed["hardware_info"]:
self.embed["hardware_info"]["cpu"] = ( try:
re.search(r"CPU:\s([^;\n\r]*)", log_file, re.MULTILINE) if setting == "cpu":
.group(1) self.embed["hardware_info"][setting] = (
.rstrip() re.search(r"CPU:\s([^;\n\r]*)", log_file, re.MULTILINE)
) .group(1)
self.embed["hardware_info"]["ram"] = ( .rstrip()
re.search(r"RAM:(\sTotal)?\s([^;\n\r]*)", log_file, re.MULTILINE) )
.group(2) if setting == "ram":
.rstrip() self.embed["hardware_info"][setting] = (
) re.search(
self.embed["hardware_info"]["os"] = ( r"RAM:(\sTotal)?\s([^;\n\r]*)", log_file, re.MULTILINE
re.search(r"Operating System:\s([^;\n\r]*)", log_file, re.MULTILINE) )
.group(1) .group(2)
.rstrip() .rstrip()
) )
self.embed["hardware_info"]["gpu"] = ( if setting == "os":
re.search( self.embed["hardware_info"][setting] = (
r"PrintGpuInformation:\s([^;\n\r]*)", log_file, re.MULTILINE re.search(
) r"Operating System:\s([^;\n\r]*)",
.group(1) log_file,
.rstrip() re.MULTILINE,
) )
except AttributeError: .group(1)
pass .rstrip()
)
if setting == "gpu":
self.embed["hardware_info"][setting] = (
re.search(
r"PrintGpuInformation:\s([^;\n\r]*)",
log_file,
re.MULTILINE,
)
.group(1)
.rstrip()
)
except AttributeError:
continue
def get_ryujinx_info(log_file=log_file): def get_ryujinx_info(log_file=log_file):
try: # try:
self.embed["emu_info"]["ryu_version"] = [ for setting in self.embed["emu_info"]:
line.split()[-1] try:
for line in log_file.splitlines() if setting == "ryu_version":
if "Ryujinx Version:" in line self.embed["emu_info"][setting] = [
][0] line.split()[-1]
self.embed["emu_info"]["logs_enabled"] = ( for line in log_file.splitlines()
re.search(r"Logs Enabled:\s([^;\n\r]*)", log_file, re.MULTILINE) if "Ryujinx Version:" in line
.group(1) ][0]
.rstrip() if setting == "logs_enabled":
) self.embed["emu_info"][setting] = (
self.embed["emu_info"]["ryu_firmware"] = [ re.search(
line.split()[-1] r"Logs Enabled:\s([^;\n\r]*)", log_file, re.MULTILINE
for line in log_file.splitlines() )
if "Firmware Version:" in line .group(1)
][0] .rstrip()
except (AttributeError, IndexError): )
pass if setting == "ryu_firmware":
self.embed["emu_info"]["ryu_firmware"] = [
line.split()[-1]
for line in log_file.splitlines()
if "Firmware Version:" in line
][0]
except (AttributeError, IndexError):
continue
def format_log_embed(): def format_log_embed():
cleaned_game_name = re.sub( cleaned_game_name = re.sub(
@ -181,6 +201,11 @@ class LogFileReader(Cog):
5) Upload the latest log file.""", 5) Upload the latest log file.""",
inline=False, inline=False,
) )
log_embed.add_field(
name="Latest Error Snippet",
value=self.embed["game_info"]["errors"],
inline=False,
)
else: else:
log_embed.add_field( log_embed.add_field(
name="Latest Error Snippet", name="Latest Error Snippet",
@ -226,7 +251,7 @@ class LogFileReader(Cog):
"-1": "Custom", "-1": "Custom",
"1": "Native (720p/1080p)", "1": "Native (720p/1080p)",
"2": "2x (1440p/2160p)", "2": "2x (1440p/2160p)",
"3": "3x (2160p/31240p)", "3": "3x (2160p/3240p)",
"4": "4x (2880p/4320p)", "4": "4x (2880p/4320p)",
} }
setting[name] = resolution_map[setting_value] setting[name] = resolution_map[setting_value]
@ -304,41 +329,69 @@ class LogFileReader(Cog):
elif line[0] == " " or line == "": elif line[0] == " " or line == "":
curr_error_lines.append(line) curr_error_lines.append(line)
def error_search(search_term): def error_search(search_terms):
found_term = bool( for term in search_terms:
[ for error_lines in errors:
line line = "\n".join(error_lines)
for line in errors if term in line:
if any(search_term in string for string in line) return True
]
)
return found_term
shader_cache_collision = error_search("Cache collision found") return False
dump_hash_warning = error_search("ResultFsInvalidIvfcHash")
shader_cache_collision = error_search(["Cache collision found"])
dump_hash_warning = error_search(["ResultFsInvalidIvfcHash"])
shader_cache_corruption = error_search(
[
"""Object reference not set to an instance of an object.
at Ryujinx.Graphics.Gpu.Shader.ShaderCache.Initialize()""",
"System.IO.InvalidDataException: End of Central Directory record could not be found",
]
)
last_errors = "\n".join( last_errors = "\n".join(
errors[-1][:2] if "|E|" in errors[-1][0] else "" errors[-1][:2] if "|E|" in errors[-1][0] else ""
) )
except IndexError: except IndexError:
last_errors = None last_errors = None
return (last_errors, shader_cache_collision, dump_hash_warning) return (
last_errors,
shader_cache_collision,
dump_hash_warning,
shader_cache_corruption,
)
# Finds the lastest error denoted by |E| in the log and its first line # Finds the lastest error denoted by |E| in the log and its first line
# Also warns of shader cache collisions # Also warns of common issues
( (
last_error_snippet, last_error_snippet,
shader_cache_warn, shader_cache_warn,
dump_hash_warning, dump_hash_warning,
shader_cache_corruption_warn,
) = analyse_error_message() ) = analyse_error_message()
if last_error_snippet: if last_error_snippet:
self.embed["game_info"]["errors"] = f"```{last_error_snippet}```" self.embed["game_info"]["errors"] = f"```{last_error_snippet}```"
else: else:
pass pass
# Game name parsed last so that user settings are visible with empty log
self.embed["game_info"]["game_name"] = (
re.search(
r"Loader LoadNca: Application Loaded:\s([^;\n\r]*)",
log_file,
re.MULTILINE,
)
.group(1)
.rstrip()
)
if shader_cache_warn: if shader_cache_warn:
shader_cache_warn = f"⚠️ Cache collision detected. Investigate possible shader cache issues" shader_cache_warn = f"⚠️ Cache collision detected. Investigate possible shader cache issues"
self.embed["game_info"]["notes"].append(shader_cache_warn) self.embed["game_info"]["notes"].append(shader_cache_warn)
if shader_cache_corruption_warn:
shader_cache_corruption_warn = f"⚠️ Cache corruption detected. Investigate possible shader cache issues"
self.embed["game_info"]["notes"].append(
shader_cache_corruption_warn
)
if dump_hash_warning: if dump_hash_warning:
dump_hash_warning = f"⚠️ Dump error detected. Investigate possible bad game/firmware dump issues" dump_hash_warning = f"⚠️ Dump error detected. Investigate possible bad game/firmware dump issues"
self.embed["game_info"]["notes"].append(dump_hash_warning) self.embed["game_info"]["notes"].append(dump_hash_warning)