feat: show function calls on error

This commit is contained in:
2026-07-05 17:22:09 +08:00
parent 247a9a8770
commit 0a10c61c59
+43
View File
@@ -20,6 +20,46 @@ else:
from module.device.platform.platform_base import PlatformBase as Platform
def show_function_call():
"""
INFO 21:07:31.554 │ Function calls:
<string> L1 <module>
spawn.py L116 spawn_main()
spawn.py L129 _main()
process.py L314 _bootstrap()
process.py L108 run()
process_manager.py L149 run_process()
alas.py L285 loop()
alas.py L69 run()
src.py L55 rogue()
rogue.py L36 run()
rogue.py L18 rogue_once()
entry.py L335 rogue_world_enter()
path.py L193 rogue_path_select()
"""
import os
import traceback
stack = traceback.extract_stack()
func_list = []
for row in stack:
filename, line_number, function_name, _ = row
filename = os.path.basename(filename)
# /tasks/character/switch.py:64 character_update()
func_list.append([filename, str(line_number), function_name])
max_filename = max([len(row[0]) for row in func_list])
max_linenum = max([len(row[1]) for row in func_list]) + 1
def format_(file, line, func):
file = file.rjust(max_filename, " ")
line = f'L{line}'.rjust(max_linenum, " ")
if not func.startswith('<'):
func = f'{func}()'
return f'{file} {line} {func}'
func_list = [f'\n{format_(*row)}' for row in func_list]
logger.info('Function calls:' + ''.join(func_list))
class Device(Screenshot, Control, AppControl, Platform):
_screen_size_checked = False
detect_record = set()
@@ -104,6 +144,7 @@ class Device(Screenshot, Control, AppControl, Platform):
if not reached:
return False
show_function_call()
logger.warning('Wait too long')
logger.warning(f'Waiting for {self.detect_record}')
self.stuck_record_clear()
@@ -155,11 +196,13 @@ class Device(Screenshot, Control, AppControl, Platform):
count[key] = count.get(key, 0) + 1
count = sorted(count.items(), key=lambda item: item[1])
if count[0][1] >= 12:
show_function_call()
logger.warning(f'Too many click for a button: {count[0][0]}')
logger.warning(f'History click: {[str(prev) for prev in self.click_record]}')
self.click_record_clear()
raise GameTooManyClickError(f'Too many click for a button: {count[0][0]}')
if len(count) >= 2 and count[0][1] >= 6 and count[1][1] >= 6:
show_function_call()
logger.warning(f'Too many click between 2 buttons: {count[0][0]}, {count[1][0]}')
logger.warning(f'History click: {[str(prev) for prev in self.click_record]}')
self.click_record_clear()